正在嘗試一個本地通知演示,並在我的iPhone徽章&警報通知工作除了sound.Here好是我的代碼,的iOS 8:聲音設置不起作用的UIUserNotificationType
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 - >通知並啓用警報,徽章&聲音,即使在當時的聲音通知不存在的
任何幫助,將不勝感激。
我剛纔在模擬器嘗試....但沒有用途..它沒有工作:( –