didReceiveRemoteNotification

didReceiveRemoteNotification

本文介绍了Apple 的静默推送通知可以在后台启动我的应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Apple 的文档,我可以通过在 aps 负载字典中添加 "content-available" = 1 键值来注册静默通知.我希望我的应用程序在无提示通知到达时在后台唤醒.我在 info.plist

中将 App downloads content in response to push notification 值设置为 Required background patterns

这是我的有效载荷字典

{"aps":{警报":通知警报",徽章":1,声音":默认",内容可用":1}}

我在 -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 中得到回调 而我的应用程序在后台.但我的问题是,当我们的应用程序处于终止状态时,我们可以回调这个方法或任何其他方法吗?

我不希望我的应用用户看到通知,但我希望我的应用通过静默通知在后台唤醒来执行某些任务.

如有任何建议,我们将不胜感激.

解决方案

当设备收到设置了 content-available 的推送消息时,Apple 在后台启动您的应用.用户不会意识到这一点.来自文档:>

content-available:为该键提供值 1 以指示新内容可用.包含这个键和值意味着当你的应用在后台启动或恢复时,-application:didReceiveRemoteNotification:fetchCompletionHandler:被调用.

同样来自文档

didReceiveRemoteNotification:但是,如果用户已经强行退出了.在这种情况下,用户必须重新启动您的应用或在系统尝试启动您的应用程序之前重新启动设备再次自动.

According to Apple's documentation I can register for silent notification by adding "content-available" = 1 key-value in aps payload dictionary. I want my app to wake up in background when a silent notification arrives. I set App downloads content in response to push notifications value to Required background modes in my info.plist

This is my payload dictionary

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

I am getting callbacks in -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler while my app is in background. But my question is can we get callback to this or any other method when our application is in killed state?

I don't want my app user to see the notification but I want my app to perform certain task by waking it up in background through silent notifications.

Any suggestions would be appreciated.

解决方案

When the device receives a push message with content-available set, your app gets launched in the background by Apple. Users won't be aware of it. From the docs:

Also from docs

这篇关于Apple 的静默推送通知可以在后台启动我的应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:17