Flycut/Flycut-iOS/AppDelegate.swift
Mark Jerde 99d471f46a Extend Settings access to Flycut iOS
Use InAppSettingsKit to display Settings within the app in addition to within
Settings.app.  This allows changes that initiate a user prompt to prompt the
user immediately when the change is made, rather than upon app launch as is the
case with using Settings.app, providing better user experience.

Move acknowledgements from preferences panel into a text file that is sourced into the preferences panel on macOS and the settings bundle (in-app only) on iOS.
2018-10-30 23:05:03 -05:00

80 lines
3.5 KiB
Swift

//
// AppDelegate.swift
// Flycut-iOS
//
// Created by Mark Jerde on 7/12/17.
//
//
import UIKit
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options:[]) { (granted, error) in
// Enable or disable features based on authorization.
}
application.registerForRemoteNotifications()
let fileRoot = Bundle.main.path(forResource: "acknowledgements", ofType: "txt")
let contents = try? String.init(contentsOfFile: fileRoot!, encoding: String.Encoding.utf8)
UserDefaults.standard.set(contents, forKey: "acknowledgementsText")
return true
}
// Called by push notifications when a CloudKit change occurs.
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// Notification was generated by CloudKit changes, so check for updates.
MJCloudKitUserDefaultsSync.checkCloudKitUpdates()
// Signal that we have completed our response to notification, with
// parameter assuming that we received new data.
completionHandler(.newData)
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
print(deviceTokenString)
MJCloudKitUserDefaultsSync.setRemoteNotificationsEnabled(true)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("i am not available in simulator \(error)")
MJCloudKitUserDefaultsSync.setRemoteNotificationsEnabled(false)
}
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.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}