我收到推送通知列表。如果用户选择通知,我想从通知列表中获取所选通知中的数据
提前致谢
答案 0 :(得分: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);
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];
}
}
答案 1 :(得分:0)
for Swift :通知数据已在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;
}
答案 2 :(得分: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);
// 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;
}