ios - 收到带有数据的远程通知时激活 iOS 应用程序

标签 ios iphone swift ipad

我正在为双因素身份验证创建一个 iOS 应用程序。 我有一个用户登录的系统,我的服务器通过远程通知(推送消息)向我的 iOS 应用程序发送质询。

当应用程序未激活时,我能够收到推送通知,所以没问题。 我无法做的是激活我的应用程序。我不知道该怎么做。 推送消息包含结构化数据(不是简单的警报文本消息)。

这可能吗?我可以在推送消息中设置一些标志吗?或者这是违反 iOS 准则的事情之一?

最佳答案

转到应用程序设置 -> 功能并为您的应用程序打开后台模式。检查最后一个选项,远程通知, 要了解更多信息,请查看本教程: This raywenderlich tutorial is all u need to get up and running with push notification


如果这不起作用,请将 : 'content_available' => true 添加到您的推送通知参数 例如:

{
   "alert" :"",
    "badge" :"787",
      "Content-available" : "1" // or true,
       "sound" : ""
        }

如果您为该键提供值 1,(如果用户打开您的应用程序处于后台或已恢复)将调用 application:didReceiveRemoteNotification:fetchCompletionHandler:。

根据 RemoteNotifications Programming content-available 的定义是

Provide this key with a value of 1 to indicate that new content is available. Including this key and value means that when your app is launched in the background or resumed, application:didReceiveRemoteNotification:fetchCompletionHandler: is called.(Newsstand apps are guaranteed to be able to receive at least one push with this key per 24-hour window.)

关于ios - 收到带有数据的远程通知时激活 iOS 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51192737/

相关文章:

ios - 函数主体运行次数与我呈现 ViewController 的次数一样多

ios - 使用Monaca提交iOS应用

iphone - 我的应用程序是 "contain encryption"吗?

iphone - 如何相对于屏幕 iPhone 的一侧锚定 View

iphone - iPhone 文本编辑器上的语法突出显示

Swift:将字符串转换为 NSTextField

基于 iPhone View 的应用程序转到主视图

ios - 出现红线错误 "Thread 1: signal SIGTERM"时如何调试

ios - 如何从Firebase Storage下载并声明大量图像?

swift - Alamofire 库不响应 Swift 包管理器