Unverified Commit 40d3b674 authored by Zach Knox's avatar Zach Knox
Browse files

Background App Refresh

parent 32f02bde
......@@ -3,7 +3,6 @@ CLANG_CXX_LANGUAGE_STANDARD = c++14
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = NO
CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/Realm
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Crashlytics" "${PODS_ROOT}/Headers/Public/Fabric"
LIBRARY_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Realm/core"
OTHER_CPLUSPLUSFLAGS = -isystem "${PODS_ROOT}/Realm/include/core" -fvisibility-inlines-hidden
OTHER_LDFLAGS = -l"c++" -l"realmcore-ios" -l"z" -framework "Security"
......
......@@ -2,7 +2,6 @@ APPLICATION_EXTENSION_API_ONLY = YES
CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/RealmSwift
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/Realm"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Crashlytics" "${PODS_ROOT}/Headers/Public/Fabric"
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
......
......@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.2</string>
<key>CFBundleVersion</key>
<string>49</string>
<string>74</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
......
......@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.2</string>
<key>CFBundleVersion</key>
<string>49</string>
<string>74</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
......
......@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.2</string>
<key>CFBundleVersion</key>
<string>49</string>
<string>73</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>
......
......@@ -38,6 +38,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
defaults.set("Apple Maps", forKey: "mapsApp")
}
application.setMinimumBackgroundFetchInterval(TimeInterval(exactly: 60)!)
return true
}
......@@ -105,6 +107,55 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
defaults.set([String: Bool](), forKey: "campuses")
}
}
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
WOPDownloadController.performDownload(completion: { facilities in
if facilities != nil {
WOPDownloadController.performAlertsDownload(completion: { alerts in
if alerts != nil {
DispatchQueue.main.async {
let date = Date()
let realm = try! Realm(configuration: WOPDatabaseController.getConfig())
let results = realm.objects(WOPFacilitiesModel.self)
if results.count == 0 {
let model = WOPFacilitiesModel()
for f in facilities! {
model.facilities.append(f)
}
for a in alerts! {
model.alerts.append(a)
}
model.lastUpdated = date
try! realm.write {
realm.add(model)
}
completionHandler(UIBackgroundFetchResult.newData)
}
else {
let fromRealm = results[0]
try! realm.write {
fromRealm.facilities.removeAll()
for f in facilities! {
fromRealm.facilities.append(f)
}
for a in alerts! {
fromRealm.alerts.append(a)
}
fromRealm.lastUpdated = date
}
}
completionHandler(UIBackgroundFetchResult.newData)
}
} else {
completionHandler(UIBackgroundFetchResult.failed)
}
})
} else {
completionHandler(UIBackgroundFetchResult.failed)
}
})
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
......
......@@ -62,6 +62,10 @@
<array>
<string>WOPViewFacilityIntent</string>
</array>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
......
......@@ -6,6 +6,7 @@
// Copyright © 2017 SRCT. Some rights reserved.
//
#if os(iOS)
import UIKit
import StoreKit
import MapKit
......@@ -139,3 +140,4 @@ public class WOPFacilityDetailViewController: UIViewController, UITableViewDeleg
}
}
}
#endif
......@@ -6,6 +6,7 @@
// Copyright © 2017 SRCT. All rights reserved.
//
#if os(iOS)
import UIKit
......@@ -52,3 +53,4 @@ public extension WOPPaddedUILabel {
}
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment