0

通知通知不工作,我發送推送通知如下:的iOS推送如果我已經在我的應用程序關閉,如果「APS」在JSON

{ 
    "alert" : "Hello, world!", 
    "sound" : "default" 
} 

我的應用程序正確地接收推送通知。但是,如果我發送此:

{ 
    "aps" : { 
     "alert" : "Hello, world!", 
     "sound" : "default" 
    } 
} 

我的應用程序從不顯示通知。

如果我的應用程序打開時我收到這最後通知正確委託didReceiveRemoteNotification userInfo: [NSObject : AnyObject]

爲什麼iOS 8的未解析這最後的通知,並表示類似的通知呢?

回答

1

沒有實際發送通知的代碼,它不完全清楚問題出在哪裏,因爲如果您使用某個庫或包裝器,它可能會添加aps條目本身。現在,你應該繼續發送通知作爲第一個例子,你也將獲得他們在didReceiveRemoteNotification userInfo: [NSObject : AnyObject]

+0

問題是關於第三方服務。他們在JSON推送通知中添加「aps:」。非常感謝 – davidrelgr

+0

歡迎您! – Azat

0

客觀C. 看看你有接到的JSON正確。對於第一個選項你已經使用我認爲這樣的代碼

(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification { 


} 

這將接收字典,你有。但是,第二個選擇您所發出的數組,其第一個指數的字典,以便與NSArray中更換的NSDictionary然後接收陣列

第一指數&找回這樣

(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSArray *)notification { 

...... 

    } 

對於斯威夫特這些代碼的工作字典爲了我。

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
     println("Push Received") 
     println(userInfo) 
     println(userInfo["aps"]) 

     var state: UIApplicationState = application.applicationState 

     if state == UIApplicationState.Active { 

      println(userInfo) 
      println(userInfo["aps"]) 

      var alert2 = UIAlertController(title: "Push", message: "Received", preferredStyle: UIAlertControllerStyle.Alert) 
      alert2.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { action in 

      })) 



     } 
相關問題