iOS 8:声音设置不适用于UIUserNotificationType

时间:2015-08-28 12:37:11

标签: ios swift ios8 uilocalnotification

我正在尝试本地通知演示,并在我的iphone中使用徽章&除了声音之外,警报通知效果很好。这是我的代码,

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

       func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {

            let notificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
            let settings = UIUserNotificationSettings(forTypes: notificationType, categories: nil)
            application.registerUserNotificationSettings(settings)

            application.applicationIconBadgeNumber = 0  // resetting the badge number to again 0

            return true
        }

        func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {

            application.applicationIconBadgeNumber = 0  //resetting the badge number to again 0

        }

这是mainviewcontroller代码片段

class ViewController: UIViewController {


    @IBAction func startNotification(sender: UIButton) {

        var localNotification = UILocalNotification()
        localNotification.fireDate = NSDate(timeIntervalSinceNow: 5)  // notification will be sent after 5 seconds from clicking
        localNotification.alertBody = "Notification came"
        localNotification.timeZone = NSTimeZone.defaultTimeZone() // Time zone of the notfication's fire date
        localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1 //The number to diplay on the icon badge. We will increment this number by one.

        UIApplication.sharedApplication().scheduleLocalNotification(localNotification) // scheduling the notification

    }

注意:即使我去了设置 - > demoApp - >通知和启用提醒,徽章和&声音,即使没有发出声音通知

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:0)

尝试在模拟器上测试?如果它在模拟器中工作而不在设备中,请确保静音开关未打开

答案 1 :(得分:0)

最后我的问题得到了解决,

1)此行必须在您的代码中

localNotification.soundName = UILocalNotificationDefaultSoundName 

2)确保不打扰模式为"关闭" (从底部向上滑动手机,您将看到半月形符号)

3)这个错误就是我所做的 - >>手机处于静音模式(在iPhone的一侧会有开关 靠近到音量按钮

4)转到设置 - >通知 - >你的申请 - >启用允许通知

5)转到设置 - >通知 - >你的申请 - >启用声音

6)使用侧面的音量按钮增加铃声音量..

希望这可能对其他人有帮助.....:)