2014-10-31 71 views
0

我允许remote and local notifications在我的应用程序中,它工作得很好remote notifications,但试图使用local notifications它然后不显示通知,但它正在运行的代码。UILocalNotification需要许可显示,但它已被授予

当我离开应用程序时,远程通知工作,但当我在应用程序中时本地通知不想显示?

下面是代码:

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

那你怎么能自己添加一个横幅? – Haring10 2014-10-31 19:27:24

+0

“添加横幅”是什么意思?你在做什么/希望做什么? – matt 2014-10-31 19:37:41

+0

你知道UIAlertController(旧的UIAlertView)吗?那是你在找什么?当我说“你可以提醒用户”时,这就是我的意思。 – matt 2014-10-31 19:40:15