mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-05-28 06:36:05 +08:00
bg fetch
This commit is contained in:
@@ -33,6 +33,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
rootNavigationManager.resetRootViewController(userSession: sessionManager.userSession)
|
||||
NetworkActivityIndicatorManager.shared.isEnabled = true
|
||||
Styles.setupAppearance()
|
||||
BackgroundNotificationFetch.configure(application: application)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -51,5 +52,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
||||
BackgroundNotificationFetch.fetch(application: application, handler: completionHandler)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
42
Classes/Systems/BackgroundNotificationFetch.swift
Normal file
42
Classes/Systems/BackgroundNotificationFetch.swift
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// BackgroundNotificationFetch.swift
|
||||
// Freetime
|
||||
//
|
||||
// Created by Ryan Nystrom on 8/12/17.
|
||||
// Copyright © 2017 Ryan Nystrom. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
final class BackgroundNotificationFetch {
|
||||
|
||||
private static let key = "com.freetime.backgroundnotificationfetch.enabled"
|
||||
static var isEnabled: Bool {
|
||||
get {
|
||||
return UserDefaults.standard.bool(forKey: BackgroundNotificationFetch.key)
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: BackgroundNotificationFetch.key)
|
||||
}
|
||||
}
|
||||
|
||||
static func configure(application: UIApplication) {
|
||||
application.setMinimumBackgroundFetchInterval(isEnabled ? 30 * 60: UIApplicationBackgroundFetchIntervalNever)
|
||||
}
|
||||
|
||||
static func fetch(application: UIApplication, handler: (UIBackgroundFetchResult) -> Void) {
|
||||
let manager = GithubSessionManager()
|
||||
guard let session = manager.userSession else { return }
|
||||
let client = newGithubClient(sessionManager: manager, userSession: session)
|
||||
client.request(GithubClient.Request(
|
||||
path: "notifications",
|
||||
method: .get,
|
||||
parameters: ["all": "false"],
|
||||
completion: { (response, _) in
|
||||
if let notes = response.value as? [ [String: Any] ] {
|
||||
application.applicationIconBadgeNumber = notes.count
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,6 +37,7 @@
|
||||
2919295F1F3FD1F40012067B /* IssuePatchContentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2919295E1F3FD1F40012067B /* IssuePatchContentViewController.swift */; };
|
||||
291929611F3FD2960012067B /* DiffString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291929601F3FD2960012067B /* DiffString.swift */; };
|
||||
291929631F3FF0DA0012067B /* StyledTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291929621F3FF0DA0012067B /* StyledTableCell.swift */; };
|
||||
291929671F3FF9C50012067B /* BackgroundNotificationFetch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291929661F3FF9C50012067B /* BackgroundNotificationFetch.swift */; };
|
||||
292484B81F01CB5C0054FE20 /* SwipeCellKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 292484B71F01CB5C0054FE20 /* SwipeCellKit.framework */; };
|
||||
292484B91F01CB5C0054FE20 /* SwipeCellKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 292484B71F01CB5C0054FE20 /* SwipeCellKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
2928C7881F15D7C50000D06D /* IssueRenamedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2928C7871F15D7C50000D06D /* IssueRenamedModel.swift */; };
|
||||
@@ -344,6 +345,7 @@
|
||||
2919295E1F3FD1F40012067B /* IssuePatchContentViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssuePatchContentViewController.swift; sourceTree = "<group>"; };
|
||||
291929601F3FD2960012067B /* DiffString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiffString.swift; sourceTree = "<group>"; };
|
||||
291929621F3FF0DA0012067B /* StyledTableCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StyledTableCell.swift; sourceTree = "<group>"; };
|
||||
291929661F3FF9C50012067B /* BackgroundNotificationFetch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackgroundNotificationFetch.swift; sourceTree = "<group>"; };
|
||||
292484B71F01CB5C0054FE20 /* SwipeCellKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwipeCellKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2928C7871F15D7C50000D06D /* IssueRenamedModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueRenamedModel.swift; sourceTree = "<group>"; };
|
||||
2928C7891F15D7E00000D06D /* IssueRenamedCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueRenamedCell.swift; sourceTree = "<group>"; };
|
||||
@@ -1072,7 +1074,9 @@
|
||||
29316DC41ECC9841007CAE3F /* Alamofire+GithubAPI.swift */,
|
||||
297AE8671EC0D5C200B44A1F /* AppDelegate.swift */,
|
||||
290744B01F250A1D00FD9E48 /* Autocomplete */,
|
||||
291929661F3FF9C50012067B /* BackgroundNotificationFetch.swift */,
|
||||
29C167791ECA14F700439D62 /* Feed.swift */,
|
||||
54AD5E8D1F24D953004A4BD6 /* FeedSelectionProviding.swift */,
|
||||
29C167731ECA0DBB00439D62 /* GithubAPIDateFormatter.swift */,
|
||||
29C0E7061ECBC6C50051D756 /* GithubClient.swift */,
|
||||
299C06D91F0DD87F00C2828E /* GithubClient+Paging.swift */,
|
||||
@@ -1086,7 +1090,6 @@
|
||||
29316DCC1ECD31E9007CAE3F /* StatusBar.swift */,
|
||||
29416BFC1F118DD700D03E1A /* String+QueryItemValue.swift */,
|
||||
292CD3CF1F0DBB5C00D3D57B /* WebviewCellHeightCache.swift */,
|
||||
54AD5E8D1F24D953004A4BD6 /* FeedSelectionProviding.swift */,
|
||||
);
|
||||
path = Systems;
|
||||
sourceTree = "<group>";
|
||||
@@ -1679,6 +1682,7 @@
|
||||
290D2A421F04D3470082E6CC /* IssueStatus.swift in Sources */,
|
||||
29A195041EC74C4800C3E289 /* Date+Display.swift in Sources */,
|
||||
295840DA1EEA07E4007723C6 /* IssueCommentQuoteCell.swift in Sources */,
|
||||
291929671F3FF9C50012067B /* BackgroundNotificationFetch.swift in Sources */,
|
||||
292FCB131EDFCC510026635E /* IssueLabelDotCell.swift in Sources */,
|
||||
292FCB1F1EDFCD750026635E /* IssueCommentReactionViewModel.swift in Sources */,
|
||||
294967531EFC1EDB00B1CF1A /* IssueCommentHtmlCell.swift in Sources */,
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1371</string>
|
||||
<string>1374</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSApplicationQueriesSchemes</key>
|
||||
|
||||
Reference in New Issue
Block a user