当我收到静默推送通知时,iOS 会唤醒我的应用程序吗?(当应用程序未处于运行状态时) [英] Will iOS awake my app when i receive silent push notification?(When app is not in running state)

查看:61
本文介绍了当我收到静默推送通知时,iOS 会唤醒我的应用程序吗?(当应用程序未处于运行状态时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新问题:

要求是;收到无提示通知后,我想运行一个网络服务并在通知栏中显示一个班轮.如果应用程序也被杀死,它必须工作.有什么解决方法吗?

我正在尝试以下方法.

我是 iOS 新手,我在无声推送通知方面苦苦挣扎,在谷歌上搜索了很多,但卡住了.当应用程序未启动时(即当应用程序从应用程序切换器中删除时)收到静默推送通知时,iOS 会唤醒我的应用程序吗?

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

我的有效载荷是

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

推荐答案

如果应用已从应用切换器中移除,iOS 将不会唤醒您的应用,因为用户明确要求关闭您的应用.

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.

如果用户至少打开您的应用一次,并且没有将其从 App Switcher 中删除,iOS 将唤醒您的应用

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.

(对这个问题进行投票表明它已经过时了)

此答案不再正确...您现在可以使用 PushKit 唤醒您的即使应用已从应用切换器中删除,应用也可以执行一些小事(例如下载小块数据以更新内容).

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.

这篇关于当我收到静默推送通知时,iOS 会唤醒我的应用程序吗?(当应用程序未处于运行状态时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆