Can UILocalNotification be used to wake up a task that is in the background

前端 未结 1 1322
走了就别回头了
走了就别回头了 2021-01-06 04:57

I would like to know, if it is possible to somehow \"wake up\" a task that is in the background, to quickly check something on the network.. I think that this could be done

相关标签:
1条回答
  • 2021-01-06 05:42

    The user has a couple of choices: #1) Do they want to see a notification for your app. #2) If notifications are enabled for your app, do they want to click on your notification to launch your app. If they do accept notifications and open your notification while your app is in the background, application:didReceiveLocalNotification is called. To be clear, the user has to accept the notification (such as sliding the slider underneath the notification)... otherwise NOTHING is called.

    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
        NSLog(@"%@", notification);
    }
    

    If your app has been terminated application:didFinishLaunchingWithOptions: is called -

    - (BOOL)application:(UIApplication *) 
    application didFinishLaunchingWithOptions:
    (NSDictionary *)launchOptions {
        UILocalNotification *theNotification = 
          [launchOptions 
            objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
        NSLog(@"%@", theNotification);
    
        return YES;
    }
    
    0 讨论(0)
提交回复
热议问题