如何从解析中注册通知以获取声音和警报? (在斯威夫特)

Posted

技术标签:

【中文标题】如何从解析中注册通知以获取声音和警报? (在斯威夫特)【英文标题】:How to register notifications from parse for sound and alerts? (in Swift) 【发布时间】:2015-03-26 21:38:27 【问题描述】:

我正在使用解析通知,但我希望通知发出警报和声音。我现在有这个:

 var pushSettings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: .Alert, categories: nil)

但是我如何也注册 .sound?在 Objective-C 中,显然是这样的:

 // Let device know you're going to be sending one of these types of notifications.
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
    (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

但是,我对 Swift 很陌生,我真的不知道如何在 Swift 中使用它!

提前致谢!

【问题讨论】:

【参考方案1】:

这应该可以...

let pushSettings = UIUserNotificationSettings(forTypes: .Alert | .Badge | .Sound, categories: nil)

【讨论】:

以上是关于如何从解析中注册通知以获取声音和警报? (在斯威夫特)的主要内容,如果未能解决你的问题,请参考以下文章

注册后向 PFUser 添加列?解析,斯威夫特

解析和斯威夫特。从 Parse 关系中设置 tableViewCell 附件类型

斯威夫特:如何延长短音的播放时间

如何从 osx 应用程序播放系统声音?

当我不注册时,推送通知仍然会播放声音

斯威夫特:ScrollRectToVisible 不工作