简体   繁体   English

推送通知和后台获取模式

[英]push notifications and background fetch mode

It's my understanding that the system will either wake you from being closed or running in the background, and allow you to fetch BEFORE it displays the system alert to the user. 据我了解,该系统会唤醒您关闭它或使其在后台运行,并允许您在向用户显示系统警报之前进行提取。

I have to download some data to show the user when they tap a push notification. 我必须下载一些数据以在用户点击推送通知时向他们显示。

I am seeing my fetch activities being performed WHILE the push is shown to the user. 我看到我的提取活动正在执行,同时向用户显示了推送。 It is allowing user to tap the notification and launch the app before we've completed the data fetch. 它允许用户在我们完成数据获取之前点击通知并启动应用程序。

Is this correct? 这个对吗?

I didn't have the chance to use push notifications and background fetch mode myself, 我本人没有机会使用推送通知和后台获取模式,

but according to the docs : 但根据文档

the system sends the notification to your app (launching it if needed)
and gives it a few moments to process the notification before displaying
anything to the user. You can use those few moments 
to download content related to the push notification and
be ready to display it to the user.

so as i understand you are suppose to have some time to react (download data) to a notification before presenting something to the user and not while the notification is shown 因此,据我了解,您应该向用户呈现某些内容之前而不是在显示通知时有一定时间对通知做出反应(下载数据)

the docs don't mention what is considered "few moments" (not that i have seen). 该文档没有提到什么是“几个时刻”(不是我所见)。

so maybe the download operation is taking more than those "few moments" 因此,下载操作所花费的时间可能比“几分钟”要多

hope this helps 希望这可以帮助

Using so-called "silent" push notification in iOS7 you can send specific silent push from your server. 使用iOS7中的所谓“静默”推送通知,您可以从服务器发送特定的静默推送。 You need to add additional key content-available in your aps dictionary 您需要添加其他关键内容-在您的aps词典中可用

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

Then you need to set two background modes in your project: Remote notifications and Background fetch. 然后,您需要在项目中设置两种后台模式:远程通知和后台获取。

Now every remote push will call for 现在,每次远程推送都会要求

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

and you can implement any background logic here. 您可以在此处实现任何后台逻辑。 For example you can start some fetch process (no longer then 30 seconds!), show custom local notification (which substitutes for standard remote on-screen push) at the moment or on fetch completion. 例如,您可以启动某些提取过程(不超过30秒!),在此刻或提取完成时显示自定义本地通知(代替标准的远程屏幕推送)。

Be sure that push notifications are allowed for your app in Notification center and that you allow Background App Refresh for your app in Settings/General. 确保在通知中心中为您的应用程序允许推送通知,并在“设置/常规”中为您的应用程序允许后台应用程序刷新。

Another important thing is that silent pushes work until you unload you app from background manually (double tap on home button). 另一个重要的事情是,无声推送会一直起作用,直到您从后台手动卸载应用程序为止(双击主屏幕按钮)。

Note that this silent mechanism worked incorrectly until iOS7.1 请注意,此静音机制在iOS7.1之前无法正常工作

You are in control to choose if to show the AlertView even if using third party like UrbanAirShip. 您可以选择是否显示AlertView,即使使用UrbanAirShip之类的第三方也是如此。 Any how, you can decide not to show it, initiate background fetch with completion block. 无论如何,您可以决定不显示它,并使用完成块启动后台获取。 After that you can use local notification to show what ever data you need to show. 之后,您可以使用本地通知来显示需要显示的数据。

Behaviour is little different in iOS 7 and below it. 行为在iOS 7及其以下版本中几乎没有什么不同。

If you can provide some more code/implementation I might be able to help a bit more. 如果您可以提供更多的代码/实现,我也许可以提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM