Will iOS awake my app when i receive silent push notification?(When app is not in running state)

前端 未结 4 747
盖世英雄少女心
盖世英雄少女心 2020-12-09 22:38

Update Question :

The requirement is; as soon as I receive silent notification, I want to run a web service and show the one liner in the notification bar.

相关标签:
4条回答
  • 2020-12-09 22:51

    If the App has been removed from the App Switcher, iOS will not awake your app, since the user specifically asked for closing your app.

    If the user open your app at least once, and do not remove it from App Switcher, iOS will awake your app

    What we have done server-side to handle this is : If the user's app doesn't connect in the minute after we sent the silent notification, (you can set it as you wish), we send another non-silent push notification to alert the user. Since the App (is not closed by the user) should automatically fetch data, it should take under a minute.

    But for that of course you need a more complex server code than simply sending silent push.

    EDIT : (Getting a vote up on this question showed me that it was outdated)

    This answer is no longer True... you can now with PushKit wake up your app to do some minor things (like downloading small chunks of data to update content) even if the App has been removed from App Switcher.

    0 讨论(0)
  • 2020-12-09 22:55

    You CAN get a PUSH-notification and work with it. I know a little way to do this... Open the AppDelegate.m and and find or put this method - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions. After that, put into this method code like mine:

    NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    
    if (userInfo) {
        NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
    
        NSString *alertType = [apsInfo objectForKey:@"type"]; //my own param in PUSH-notification
        globalPushType = alertType;  //global variable for working with it in some ViewControllers after app's load
    }
    

    I know, this helps a lot of people. =)

    0 讨论(0)
  • 2020-12-09 23:06

    As far I have tested when the app is terminate by the user (swiping up from the app switcher) you won't have background execution time due to silent push flag (content-available) or background fetch.

    Also this:

    Also keep in mind that if you kill your app from the app switcher (i.e. swiping up to kill the app) then the OS will never relaunch the app regardless of push notification or background fetch. In this case the user has to manually relaunch the app once and then from that point forward the background activities will be invoked. -pmarcos (Apple worker)

    From apple forums: https://devforums.apple.com/message/873265#873265

    0 讨论(0)
  • 2020-12-09 23:09

    Please checkout this:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveRemoteNotification:fetchCompletionHandler:

    Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.

    This clearly says that Using new Background Push feature you can Awake the App Only if Your app is suspended Not if it is terminated forcefully by User.

    0 讨论(0)
提交回复
热议问题