通知声音和徽章不起作用

时间:2016-07-25 12:27:14

标签: php ios push-notification swift2

我创建了一个远程推送通知,通知效果很好,但声音和徽章不起作用。在我的服务器端代码中我有:

$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

}

为什么声音和徽章不起作用?

1 个答案:

答案 0 :(得分:0)

php代码看起来没问题。在应用程序中,您是否注册了推送通知?还尝试卸载应用程序,然后重新安装它并接受应用程序的声音和徽章。

编辑:同时在您的应用设置中启用声音和徽章。

编辑2:试试这个:执行:let types:UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]然后application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: types, categories: nil))您必须为警报,声音和徽章注册应用程序,但您只注册了警报。

相关问题