2016-08-11 47 views
1

目前我使用的是所謂的「耳語」是應該與顯示應用程序內推送通知Whisper Link如何在應用程序打開時接收應用程序內推送通知?

在我的「didReceiveRemoteNotification」幫我把它設置如下庫:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
    if application.applicationState == .Active { 

     let navigationController = self.window!.rootViewController as! UINavigationController 

     if let aps = userInfo["aps"] as? NSDictionary { 
     if let alert = aps["alert"] as? NSDictionary { 
      if let title = alert["title"] as? NSString { 
      if let body = alert["body"] as? NSString { 

       let announcement = Announcement(title: title as! String, subtitle: body as! String, image: UIImage(named: "HolyGrailLogo-58")) 
       Shout(announcement, to: navigationController) 
      } 

      } 
     } 
     } 

     // Show and hide a message after delay 


    } 
    } 

由於一些奇怪的原因,我沒有收到任何推送通知,不知道爲什麼。

+0

應用程序請求用戶接受推送通知的權限嗎?您不應該檢查application.applicationState == .Active – picciano

+0

我正在檢查application.applicationState == .Active以查看如果該應用程序是打開的。用戶應該已經接受推送通知 – SwiftyJD

+0

您可以查看[此社區答案](https://support.layer.com/hc/en-us/articles/204632870-How-do-I-troubleshoot-issues-with-Push-Notifications-on-iOS-)可能的原因。 –

回答

0
  1. 檢查您的設備設置,您的應用程序能夠接收遠程通知。
  2. 將打印語句這種方法FUNC申請(申請後:UIApplication的,didReceiveRemoteNotification
  3. 如果不打印,然後問題是與你的庫
  4. 。主動不需要檢查當應用程序在後臺此。方法將不會執行
相關問題