2017-06-15 69 views
-1

我已经经历了很多帖子,回合无法弄清楚有没有办法在应用程序退出时获取推送通知。iOS - 获取推送通知当应用程序强制退出用户

我试着用content_available(true/1)和Priority为High,我听到通知声音,但没有通知徽章或App上的内容。任何线索将不胜感激。

{ to=/topics/lshekhar,          
    content_available=1,         
    collapse_key=sample, 
    delay_while_idle=true, 
    delivery_receipt_requested=true, 
    priority=10, 
    data={message={ "id" : "eARMS", 
        "submitter" : "lshekhar", 
        "topic" : "/topics/lshekhar" 
       }}, 
    time_to_live=10000, 
    notification={"sound":"default"}, 
    message_id=m-3319428685310488470, 
    badge=12} 
+0

它发生在前景或背景 –

+0

APNS我们不能在自动 –

+0

处理例如看到这个https://stackoverflow.com/questions/39382852/didreceiveremotenotification-not-called-ios-10/39383027#39383027 –

回答

1

这似乎是iOS 10中的问题。当您的有效载荷的主体密钥为空或“”(空字符串)时,会发生这种情况。

这可以很容易地与本地通知复制以及。要求您的APNS负载创建者将非空字符串添加到正文,并且通知将显示横幅。

"alert": { 
      "title": "Some title : ", 
      "body": "Some body text" 
} 

这应该可以解决您的问题。希望它可以帮助

编辑:

由于OP已要求访问通知有效载荷的方式,当应用程序被退出,应用程序接收APNS,我更新了答案

您可以访问APNS有效载荷,如果应用程序恰好收到APNS,而其退出使用的AppDelegate的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    if (launchOptions != nil) { 
     NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
     if (dictionary != nil) { 
      /*it is an APNS launch 
     } 
    } 

    ... 
} 

希望它可以帮助

+0

谢谢所以很多为您的答案。 通过单击通知它不会打开应用程序。此外,在didReceiveRemoteNotification方法中,将修改标题并保存SQL中的正文内容,这些内容将用于显示收到的通知列表。任何想法,它在应用程序退出的情况下击中哪种方法?这样我可以自定义并保存在数据库中? – leela

+0

我现在能够以下面的格式获得徽章。 {to =/topics/lshekhar.earms,content_available = true,collapse_key = sample,delay_while_idle = true,delivery_receipt_requested = true,priority = high, time_to_live = 10000, notification = {“sound”:“default”,“title “:” 工具连接”, \t \t “身体”:消息= { \t \t \t \t \t \t “ID”: “eARMS”, \t \t \t \t \t \t “提交”: “lshekhar”, \t \t \t \t \t \t“topic”:“/ topics/lshekhar。earms”, \t \t \t \t \t \t “requestname”: “的requestId - eARMS_2017-06-1515:24:20” }, \t \t “徽章”: “12”},MESSAGE_ID = M-1317505031125464473} – leela

+0

@ leela:很高兴我可以帮助:)如果应用程序退出并且您的应用程序碰巧收到通知,如果用户点击通知以打开应用程序,您的应用程序委托的didFinishLaunch with options方法的启动选项字典将具有通知字典。它通过使用UIApplicationLaunchOptionsRemoteNotificationKey :) –