我创建了一个远程推送通知,通知效果很好,但是声音和角标(Badge)不起作用。在我的服务器端代码中,我有:
$messageBody['aps'] = array('alert' => $message, 'sound' => 'default','badge' => 2);
这是 iOS 代码:
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
//print(error)
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
print(deviceToken)
}
func application(application: UIApplication, didReceiveRemoteNotificationuserInfo userInfo: [NSObject : AnyObject]) {
print(userInfo)
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
// Override point for customization after application launch.
application.registerForRemoteNotifications()
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert, categories: nil))
initLocationManager()
return true
}
为什么声音和角标(Badge)不起作用?
php 代码看起来不错。在应用程序中,您是否注册了推送通知?还可以尝试卸载该应用,然后重新安装并接受该应用的声音和角标(Badge)。
编辑:同时在您的应用设置中启用声音和角标(Badge)。
编辑 2:试试这个:做:let types:UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
然后 application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: types , categories: nil))
您必须为应用程序注册警报、声音和角标(Badge),但您只注册了警报。
关于php - 通知声音和角标(Badge)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38567776/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |