推送通知导致应用程序崩溃。

3
我正在使用IBM MobileFirst Platform Foundation 7.0创建一款支持推送通知的应用程序。目前为止,iOS设备可以在应用程序未运行时成功接收到通知。但是,如果我从通知的横幅消息中触摸,则应用程序将启动然后立即崩溃。同样,如果应用程序已经运行并且推送通知到达,则应用程序将立即崩溃。
奇怪的是,最初我并没有总是看到这种行为。然而,现在每次都会在上述情况下发生。
我该如何纠正这个问题?是否需要安装补丁?我已经卸载/重新安装了应用程序,但没有成功。
以下是我通过Worklight REST API发送的有效负载:
{
  "message" : {
    "alert" : "Test message",
  },
  "settings" : {
    "apns" : {
      "badge" : 1,
      "iosActionKey" : "Ok",
      "payload" : "",
      "sound" : "song.mp3"
    }
  },
  "target" : {
    "consumerIds" : [],
    "deviceIds" : [ ],
    "platforms" : [ "A"],
    "tagNames" : [],
  },
}

这是我的设备上的错误报告:

> apsd[93] <Error>: Property list invalid for format: 200 (property lists cannot contain objects of type 'CFNull')   [209] <Warning>:
> [DEBUG] [WL_PUSH] -[Push processRemotePushNotification:] in Push.m:426
> :: Push: didReceive Remote notification   [209] <Warning>: [FATAL]
> [WORKLIGHT] Uncaught Exception: *** -[__NSArrayI objectAtIndex:]:
> index 1 beyond bounds [0 .. 0]   [209] <Error>: *** Terminating app
> due to uncaught exception 'NSRangeException', reason: '***
>     -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'     *** First throw call stack:     (0x1863cc2d8 0x1980980e4 0x1862afb34
> 0x1002a5afc 0x1002a558c 0x1872c0180 0x18638412c 0x186383ddc
> 0x186381828 0x1862ad2d4 0x18fd036fc 0x18aeaaf40 0x1000ac0e0
> 0x198742a08)   ReportCrash[210] <Error>: task_set_exception_ports(B07,
> 400, D03, 0, 0) failed with error (4: (os/kern) invalid argument)  
> ReportCrash[210] <Notice>: ReportCrash acting against PID 209  
> ReportCrash[210] <Notice>: Formulating crash report for process [209] 
> com.apple.xpc.launchd[1]
> (UIKitApplication:com.companyname.appname.qa[0xc100][209]) <Notice>:
> Service exited due to signal: Abort trap: 6   ReportCrash[210]
> <Notice>: Saved report to
> /var/mobile/Library/Logs/CrashReporter/_2015-08-07-231518_.ips  
> SpringBoard[54] <Warning>: Application
> 'UIKitApplication:com.companyname.appname.qa[0xc100]' crashed.

尾随逗号,在目标后面,并且没有APN密钥。 - some_id
文档还列出了“actionKey”,而不是“isActionKey”:http://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.0.0/com.ibm.worklight.apiref.doc/html/refjavascript-server/html/WL.Server.html%23sendMessage - Idan Adar
处理推送通知负载的代码是什么样子的?你能在所有的异常上设置一个断点吗?这样,当出现异常时,你就可以准确地知道它来自哪一行了。 - Michael Dautermann
我仍然在收到同样的错误。我检查了json,现在我有以下内容: { "message": { "alert": "测试消息" }, "settings": { "apns": { "actionKey": "确认", "payload": "" } }, "target": { "consumerIds": [], "deviceIds": [], "platforms": [ "A" ], "tagNames": [] } }我不确定你所说的“没有apn密钥”的意思是什么...我有我的apns证书和生成的.p12文件。在json中还需要指定其他字段吗? - JM Huret
1
哇,我能够通过修正有效载荷来解决它。虽然我看到的许多示例都显示可以使用空字符串,但实际上需要一个javascript对象,否则应用程序将崩溃,或者根本不需要。现在我能够在运行应用程序时接收通知而不会导致崩溃。@IdanAdar,您知道我如何获得某种应用内响应此消息的类型,例如警报吗?我可以在控制台中看到它接收到消息,但默认情况下什么也不会发生。我需要在应用委托中定义正确的方法吗?感谢您的帮助! - JM Huret
显示剩余4条评论
1个回答

0

如果客户端接收到的有效载荷格式不正确,则预期的行为是出现问题。作为第一步,请确保有效载荷的格式与以下链接中所述的格式相匹配-

WL.Server.sendMessage

或者REST API

客户端处理程序已经在框架内定义,您不需要自己实现。要处理有效载荷,请在客户端使用适当的JS回调函数。如果使用标签/广播通知,则将使用WL.Client.Push.onMessage


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接