1

我用swift 2.2編寫了舊代碼,用於註冊和觸發UILocalNotification。現在,當我從xcode 8和IOS 9中的Swift 2.2遷移到2.3時,我無法在此之後收到任何本地通知。另外,雖然在控制檯中沒有得到任何異常。可以確認它在IOS9下工作正常。在iOS 10 + Swift中不調用本地通知2.3

UIApplication.sharedApplication().scheduleLocalNotification(notification) 

這是我用來觸發本地通知的代碼。

我可以看到文檔說這個方法已經在IOS 10中被棄用,並且需要使用UNUserNotificationCenter來代替。但要使用我需要升級到Swift 3.0。

因此,我的問題是,它是Swift 2.3中的bug /漏洞嗎?我們有什麼解決辦法嗎?或者我錯過了什麼?

+0

UILocalNotifications被棄用iOS上的10,但不揭掉已刪除,因此您仍然可以使用 –

+0

我正在使用該功能,但即使計劃它也無法收到任何通知。哪個在ios 9中可以正常工作。「 –

+0

」需要使用UNUserNotificationCenter,但要使用我需要升級到Swift 3.0「不,這完全是假的。 _Language_與_system_無關。 – matt

回答

-1

我相信2.3可以讓你訪問新的API。你應該能夠只使用新的API UNUserNotificationCenter

0

這是雨燕2.3的代碼,我用它來顯示我的應用程式iOS版10用戶本地通知:

func showLocalNotif() {  


    if #available(iOS 10, *) { 
     let content = UNMutableNotificationContent() 
     content.title = "your title" 
     content.subtitle = "your subtitle" 
     content.body = "your message to the users" 
     content.categoryIdentifier = "message" 

     //Set the trigger of the notification -- here a timer. 
     let trig = UNTimeIntervalNotificationTrigger(
      timeInterval: 100, 
      repeats: false) 

     //Set the request for the notification from the above 
     let request = UNNotificationRequest(
      identifier: "100.second.message", 
      content: content, 
      trigger: trig 

     ) 

     //Add the notification to the current notification center 
     UNUserNotificationCenter.currentNotificationCenter().addNotificationRequest(request, withCompletionHandler: addNotificationRequestHandler) 


    }} 
相關問題