2014-10-31 74 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