Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

objective c - 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 ?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...