2016-08-11 3 views
1

プッシュ通知を受け取ったときにapsペイロードを読み取って、アプリケーションを実行していない状態から起動する方法を教えてください。 これは私が試みたものです。サイドアプリデリゲートクラスで 、サイドでの機能アプリケーションが実行状態でないときにアプリケーション起動時にapsペイロードを読み取る方法

FinishedLaunching (UIApplication app, NSDictionary options) 
    if (options != null){ 
    if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey)){ 
     NSDictionary userInfo =(NSDictionary)options[UIApplication.LaunchOptionsRemoteNotificationKey]; 
     if (userInfo != null){ 
     if (null != options && options.ContainsKey(new NSString("aps"))) 
       { 
        NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary; 
      if (aps.ContainsKey(new NSString("title"))) 
         title = (aps[new NSString("title")] as NSString).ToString(); 
       } 
     } 
    } 
} 

しかし、私はデータを読み取ることができないのです。しかし

ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo) 

答えて

0

でこれを使用してください。直接データを持っているオプションのdoesntは、代わりに私は打ち上げがプッシュから起こったかLaunchOptionsRemoteNotificationKeyを形成していないかどうかを検出することができる午前内部オプション

FinishedLaunching (UIApplication app, NSDictionary options) 
    if (options != null){ 
    if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey)){ 
     NSDictionary userInfo =(NSDictionary)options[UIApplication.LaunchOptionsRemoteNotificationKey]; 
     if (userInfo != null){ 
     if (null != userInfo && userInfo .ContainsKey(new NSString("aps"))) 
       { 
        NSDictionary aps = userInfo .ObjectForKey(new NSString("aps")) as NSDictionary; 
      if (aps.ContainsKey(new NSString("title"))) 
         title = (aps[new NSString("title")] as NSString).ToString(); 
       } 
     } 
    } 
0

方法から(アクティブ/非アクティブ)私は、このように読むことができる午前アプリが実行状態にある場合には、正しい方法を見つけたあなたのapplication didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

//--------------------------------------------------- 
    //Handel Push notification 
    if (launchOptions != nil) 
    { 
     // Here app will open from pushnotification 
     //RemoteNotification 
     NSDictionary* dictionary1 = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
     //LocalNotification 
     NSDictionary* dictionary2 = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; 
     if (dictionary1 != nil) 
     { 
      //RemoteNotification Payload 
      NSLog(@"Launched from push notification: %@", dictionary1); 
      // here set you code 
     } 
     if (dictionary2 != nil) 
     { 
      NSLog(@"Launched from dictionary2dictionary2dictionary2 notification: %@", dictionary2); 
      double delayInSeconds = 7; 
      dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 
      dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
       // [self addMessageFromRemoteNotification:dictionary2 updateUI:NO]; 
      }); 
     } 

    } 
    else 
     {} 
+0

あるのuserinfoにチェックしなければなりませんでした。しかし、apnsペイロードから任意のデータを読み取ることができません – TutuGeorge

+0

ここにあなたのペイロードをペーストできますか? –

関連する問題