UILocalNotification需要显示权限,但它已被授予

时间:2014-10-31 18:42:48

标签: ios notifications uilocalnotification

我在我的应用中允许remote and local notifications,它对remote notifications完全正常,但在尝试使用local notifications时,它不显示通知,但它正在运行代码。

当我退出应用程序时,远程通知会起作用,但当我在应用程序中时,本地通知不想显示?

以下是代码:

didFinishLaunchingWithOptions方法中:

let notificationTypes:UIUserNotificationType = UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert
let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
UIApplication.sharedApplication().registerForRemoteNotifications()

并收到通知:

if(application.applicationState == UIApplicationState.Active) {
        var ln: UILocalNotification = UILocalNotification()
        ln.userInfo = userInfo
        ln.soundName = UILocalNotificationDefaultSoundName
        ln.alertBody = notification["alert"] as NSString
        ln.fireDate = NSDate()
        application.scheduleLocalNotification(ln)
        println("local")
    } else {
        PFPush.handlePush(userInfo)
    }

在应用中时,它会打印出local

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

听起来你并不完全了解当地的通知。本地通知的重点是,当您的应用程序不在最前面时,系统可以代表您通知用户。如果您的应用 最前面,系统就没有其他功能了。因此,当应用程序位于最前端时,本地通知不会向用户发出任何警报。相反,如果您的应用在本地通知触发时位于最前端,则会通知您的应用,可以根据需要提醒用户。