2017-03-01 37 views

回答

-1
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    NSLog(@"Notification Received .. Dictionary %@",userInfo); 
    NSString *user_TYP = [[NSUserDefaults standardUserDefaults]valueForKey:@"User_TYPE_LOG"]; 
    NSLog(@"Usr type == %@",user_TYP); 

    // all the data required is present in your info dictionary 

    id data1 = userInfo[@"key1"]; // user your data_type instead of id 
    id data2 = userInfo[@"key2"]; 

    if(received data == x && [user_TYP isEqualToString:@"type1"]) 
     do_something; 
    else 
     do_something_else; 

} 
+0

它不工作在ios 10 –

+0

@ Anbu.Karthik它正在工作 –

0

感謝斯威夫特:通知數據傳送到你的應用程序中application:didReceiveRemoteNotification:。 如果您想要在applicationDidBecomeActive:中處理它,您應該將其存儲在application:didReceiveRemoteNotification:中,並在applicationDidBecomeActive中再次閱讀。

當您的應用處於前臺應用:didReceiveRemoteNotification:時,您可以查詢UIApplication.sharedApplication().applicationState以確定您的應用是否已在前臺。如果是,那就馬上處理通知。

如果應用程序是通過推送通知推出,您還可以檢查

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
      // app was launched from push notification, handling it 
    let remoteNotification: NSDictionary! = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary 
    if (remoteNotification != nil) { 

    } 
} 

推動數據目標C:查詢應用程序狀態 可以查詢-[UIApplication applicationState]找出如果您的應用程序已經在前景和應用程序時,從推使用推出:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    //Check for options 
    if (launchOptions != nil) 
    { 
     //Store the data from the push. 
     dUserInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
     if (dUserInfo != nil) 
     { 
      //Do whatever you need 
     } 
    } 

    return YES; 
} 
+0

謝謝,我會嘗試這個 –

+0

十分感謝這個工作:) –

0

我所做的是

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
NSLog(@"Notification Received .. Dictionary %@",userInfo); 
NSString *user_TYP = [[NSUserDefaults standardUserDefaults]valueForKey:@"User_TYPE_LOG"]; 
NSLog(@"Usr type == %@",user_TYP); 
if ([user_TYP isEqualToString:@"type1"]) 
    { 
     //  VW_User_NOTific *VW_SER = [[VW_User_NOTific alloc]initWithNibName:@"VW_User_NOTific" bundle:nil]; 
     VW_User_NOTific *listingVC = [[VW_User_NOTific alloc] init]; 
     [(UINavigationController *)self.window.rootViewController pushViewController:listingVC animated:YES]; 
    } 
    else 
    { 
     VW_JS_Notific *listingVC = [[VW_JS_Notific alloc] init]; 
     [(UINavigationController *)self.window.rootViewController pushViewController:listingVC animated:YES]; 

    } 
}