Swift 2.0 显示带有自定义声音文件的通知的问题

Swift 2.0 issue showing notification with custom sound file

我试图让我的应用在用户收到消息时发送带有自定义声音文件的通知,但 var pushData:NSDictionary = NSDictionary(dictionaryLiteral: "New Message "+myName,"alert","KeepNotification.wav","sound") 中出现错误 Xcode 表示:无法使用类型为“(dictionaryLiteral: String, String, String, String)”

的参数列表调用类型 'NSDictionary' 的初始值设定项

我不知道那是什么意思,所以如果有人向我展示正确的代码行,我将不胜感激。

if success == true {

                //This to push notification when message is sent successful with sound ********

                var myName = PFUser.currentUser().valueForKey("profileName") as! String

                var pushData:NSDictionary = NSDictionary(dictionaryLiteral: "New Message "+myName,"alert","KeepNotification.wav","sound")

                var uQuery:PFQuery = PFUser.query()
                uQuery.whereKey("username", equalTo: otherName)

                var pushQuery:PFQuery = PFInstallation.query()
                pushQuery.whereKey("user", matchesQuery: uQuery)

                var push:PFPush = PFPush()
                push.setQuery(pushQuery)



                push.setData(pushData as [NSObject : AnyObject])
                push.sendPushInBackgroundWithBlock{

                    (success:Bool! , error:NSError!) -> Void in

                }

                print("Push Sent")
                //-----------------------------------------------------------------
                print("Message Sent" + myName)
                self.messageTextView.text = ""
                self.mLabel.hidden = false
                self.refreshResullts()


            }

        }

    }

}

谢谢,如果有任何不清楚的地方,我会编辑我的问题。

如果您尝试初始化一个 NSDictionary,那么您可以使用:

var pushData = ["alert" : "New Message "+ myName, "sound" : "KeepNotification.wav"]

请参阅 NSDictionary Class Reference 以了解可用于 NSDictionary 的所有初始化程序类型及其用法。