我创建了一个远程推送通知,该通知工作得很好,但是声音和徽章不起作用。在我的服务器端代码中,我有:
$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
}
为什么声音和徽章不起作用?
最佳答案
php代码看起来还不错。在应用程序中,您是否注册了推送通知?另外,请尝试卸载该应用程序,然后重新安装它并接受该应用程序的声音和标志。
编辑:还可以在您的应用设置中启用声音和标志。
编辑2:尝试以下操作:做:let types:UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
,然后再application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: types, categories: nil))
您必须注册该应用程序的警报,声音和徽章,但您只注册了警报。
关于php - 通知声音和徽章不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38567776/