Фоновая выборка работает на симуляторе (я вижу логи), но не работает на реальном устройстве - PullRequest
0 голосов
/ 05 июня 2018
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Fabric.with([Crashlytics.self])

    GADMobileAds.configure(withApplicationID: "ca-app-pub-8446699920686739~7829108")

   let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false]
    //ONE SIGNAL

    OneSignal.initWithLaunchOptions(launchOptions,
                                    appId: "f5854e88-0b58-495f-8d3f-e456234d",
                                    handleNotificationAction: nil,
                                    settings: onesignalInitSettings)

    OneSignal.inFocusDisplayType = OSNotificationDisplayType.notification;
    OneSignal.promptForPushNotifications(userResponse: { accepted in
        print("User accepted notifications: \(accepted)")
    })


    UIApplication.shared.statusBarStyle = .lightContent

    UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)

    mS.StartTimer()

    //NotificationCenter.default.addObserver(self, selector:#selector(AppDelegate.applicationWillTerminate(_:)), name:NSNotification.Name.UIApplicationWillTerminate, object:nil)

    NotificationCenter.default.addObserver(self, selector:#selector(AppDelegate.applicationWillEnterForeground(_:)), name:NSNotification.Name.UIApplicationWillEnterForeground, object:nil)

    return true
}

func applicationWillTerminate(_ application: UIApplication) {
   //mS.StartTimer()
}

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    self.mS.StartTimer()
    if let vc = window?.rootViewController as? LiveScores{
        vc.getLiveMatches(url : URL(string: "http://test.com/test/index.php/Service/lastLive"))
    }
    completionHandler(.newData)
}


func application(_ application: UIApplication,
                          didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                          fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void){
    completionHandler(UIBackgroundFetchResult.newData)
}
//I added to try this line
func applicationDidEnterBackground(_ application: UIApplication) {
    if let vc = window?.rootViewController as? LiveScores{
        vc.getLiveMatches(url : URL(string: "http://deneme.com/deneme/index.php/Service/lastLive"))
    }
    mS.StartTimer()
}

func applicationWillEnterForeground(_ application: UIApplication) {
    if let vc = window?.rootViewController as? LiveScores{
        vc.getLiveMatches(url : URL(string: "http://deneme.com/deneme/index.php/Service/lastLive"))
    }
    mS.StartTimer()
}
...