1. 如何实现 iOS 应用退出或者处于后台时可以收到推送消息?
答:
storeDeviceToken()
函数保存 Device Token 到云巴服务端;publish2()
、publish2ToAlias()
或者默认的publish()
、publishToAlias()
发送 APNs 消息,该参数设置详见云巴知识库的 Payload 一文,以及 iOS 官方文档。注:
publish2()
需要带有 ApnOption 参数才能成功发送 APNs 消息;而publish()
会发送默认的 APNs 消息。
2. 接收的消息,除了基本的内容(Topic 和 Message)还可以传递一些参数信息吗?
答: 开发者可以封装多个数据到 data.msg。
3. ApnOption 的 sound 和 badge 有什么作用?
答: 可在publish2ToAlias()
、publish2()
的 ApnOption 参数设置消息通知的方式。
alert 设置消息通知栏的内容;badge 设置角标;sound 设置通知的铃声。
具体参考云巴知识库的 Payload 一文,以及 iOS 官方文档,或参考 iOS demo 中有关 ApnOption 的设置方法。
答: 先将自定义的铃声文件加入你的 Xcode 工程里,然后,在推送的时候指定音频的名称即可。注意使用系统支持的音频格式。
{
"aps": {
"alert":"yunba",
"badge":3,
"sound":"bingbong.aiff"
}
}
如使用默认铃声,则为:
"sound":"default"
答: 在推送的时候可通过指定 badge 的值来改变当前的 badge(如上例);通过[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
可清除 badge 的值。
6. iOS SDKsubscribe()
的 qosLevel 参数,和 YBPublish2Option 的 qos 这两个参数有什么区别?
答:subscribe()
的 qos Level 限制该话题下接收到 message 的最大 qos 等级。 例如:当设置subscribe()
的 qosLevel 为 0,则 qos 为 1 的接收消息会降级到 qos 为 0。详见 MQTT V3.1 Protocol Specification
和 QoS 的说明。
答: 设置别名为空,并unsubscribe()
所有 Topic。
8. 当同时定义了publish()
的 data 和 ApnOption 参数中 alert 的 message,消息内容将以哪个为准?
答: 以 alert 的 message 为准。未定义 alert 时,则默认显示publish()
的 data。
答: 上传 APNs 证书;通过 YBPublish2Option 参数的 alert 设置通知栏内容、角标和声音等,具体参考 sdk 中关于pushlish2()
的介绍,也可以下载并参考 iOS demo 中 YBPublish2Option 的设置。
完整的设置方法请参考 iOS 官方文档。
10. 使用苹果电脑来生成 APNs 证书,在双击打开证书文件(*.cer)时,遇到“不能修改“System Roots”钥匙串”的提示
答:在钥匙串访问的界面左侧,选择“登录”(login),将证书文件(*.cer)拖进钥匙列表中即可。
11. 使用 iOS SDK,上传了 APNs 证书,但应用在后台时却收不到 APNs 通知?
答:
publish()
或 publish_to_alias()
会发送默认的 APNs 通知,
而 publish2()
或 publish2_to_alias()
,则必须在 opts 里填写 apn_json,才会发送 APNs 通知。最后,如果问题依然没有得到解决,请将您的 Appkey 用私聊或邮件(support@yunba.io)的方式发给我们,我们会尽快协助您找出原因。
答:可能是升级后 Device Token 改变造成的。建议按照苹果官方文档的建议,每次启动应用时检查 Device Token 并发送到服务器。
苹果官方文档:The device token is your key to sending push notifications to your app on a specific device. Device tokens can change, so your app needs to reregister every time it is launched and pass the received token back to your server. If you fail to update the device token, remote notifications might not make their way to the user’s device. Device tokens always change when the user restores backup data to a new device or computer or reinstalls the operating system. When migrating data to a new device or computer, the user must launch your app once before remote notifications can be delivered to that device.