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

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. It has to work if the app is killed also. any workaround ?

  • When I “Build for archive” in Xcode 4, where does the file go?
  • Objective-C String(yyyy-mm-dd) to NSDate
  • SKPhysicsBody Change Center of Mass
  • App size double on archiving iphone
  • Detecting iPhone camera orientation
  • Xcode 8: Preparing Archive takes forever
  • I am trying following method below.

    I am new to iOS and i struggled with silent push notification,googled a lot and got stuck.
    Will iOS awake my app when i receive silent push notification when app is not launched(i.e when app is removed from app switcher).

    my pay load is as

    { 
          aps: {
                  content-available: 1,
                  sound: ""
         }
    }
    

    .

    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler{
    
    int CA=[[[userInfo valueForKey:@"aps"] valueForKey:@"content-available"] intValue];
    
    if (CA==1) {
    
        my action...
    
    }
    
     completionHandler(UIBackgroundFetchResultNewData);
    }
    

    this method is called and works fine when app is in foreground and background.cant awake my app when app is not in running state(i.e app is not launched or killed from app switcher)..

    5 Solutions Collect From Internet About “Will iOS awake my app when i receive silent push notification?(When app is not in running state)”

    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.

    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.

    Follow below steps.

    1. Hear silent push when app is killed.

    2. When push comes (in didReceiveRemoteNotification), go for webservice call

    3. When you get data from webservice, send LOCAL PUSH (with text you get from webservice)

    Hope this is what you wanted.

    Please let me know if you need anything else.

    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

    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. =)