自定义声音远程推送通知 iOS 不起作用 [英] Custom sound remote push notification iOS not working

查看:35
本文介绍了自定义声音远程推送通知 iOS 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改远程消息的声音

I'm trying to change the sound of the remote message

我已将文件添加到我的项目中,见图 1

I've added the file into my project, see picture 1

我还将所有内容添加到我的 AppDelegate 中.在我添加的 didFinishLaunchingWithOptions 中:

I've also added everything into my AppDelegate. In the didFinishLaunchingWithOptions I've added:

 if (UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0 {
        UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Sound | .Alert | .Badge, categories: nil))
        UIApplication.sharedApplication().registerForRemoteNotifications()
    } else {
        UIApplication.sharedApplication().registerForRemoteNotificationTypes(.Badge | .Sound | .Alert)
    }

    //Clear badge
    UIApplication.sharedApplication().applicationIconBadgeNumber = 0
    UIApplication.sharedApplication().cancelAllLocalNotifications()

我实现的其他方法是:

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    let deviceTokenString = deviceToken.hexString
    println(deviceTokenString)
    let task = service.writeForNotifications(token: deviceTokenString, completionHandler: {
    })
    task.resume()
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
    println("Failed to get token: \(error)")
}

我从服务中收到的 Json 是:

The Json I received from the service is:

{"aps":{"alert":"The push message!", "sound":"ice.caf"}}

我不确定忘记更改通知声音的步骤?当我收到通知时,它总是播放默认声音.

I'm not sure whitch step I've forgotten to change the sound of the notification? When I receive a notification it always plays the default sound.

推荐答案

您确定文件已添加到包中吗?您可以通过查看 Build Phases 中的 Copy Bundle Resources 来检查这一点.

Are you sure the file is added to the bundle? You can check this by looking at the Copy Bundle Resources in Build Phases.

请参阅此图片以进行说明:

See this image for clarification:

这篇关于自定义声音远程推送通知 iOS 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆