func application(application: UIApplication,dIDReceivelocalnotification notification: UIlocalnotification) {
被称为每个触发的UIlocalnotification.所以当应用程序变得活跃时,这个方法被多次调用,因为我收到了多个UIlocalnotification.有没有办法确定哪个UIlocalnotification是应用程序打开的原因?对applicationState的检查不起作用,因为当应用程序处于非活动状态或在后台时,所有UIlocalnotification都已被接收.
非常感谢!
编辑:
作为一个很好的例子:当您从两个不同的组A和B收到WhatsApp消息,并从组A中选择推送通知时,应用程序打开后立即显示. WhatsApp和我的用例之间的区别是我有本地通知.
UIlocalnotification *notif = [[UIlocalnotification alloc] init]; notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:10]; notif.timeZone = [NSTimeZone defaultTimeZone];// set the your data with unique ID NSMutableDictionary *dict=[NSMutableDictionary new]; [dict setobject:ID forKey:@"ID"];// assignt the dictionary to user info notif.userInfo=dict; notif.alertbody = @"test Notification"; notif.soundname = UIlocalnotificationDefaultSoundname; [[UIApplication sharedApplication] schedulelocalnotification:notif];
你可以通过dIDReceivelocalnotification获得用户信息
- (voID)application:(UIApplication *)application dIDReceivelocalnotification:(UIlocalnotification *)notification{ if ([[notification.userInfo valueForKey:@"ID"] isEqualToString:@"1"]) { NSLog(@"notification ID %@",[notification.userInfo valueForKey:@"ID"]); } else if ([[notification.userInfo valueForKey:@"ID"] isEqualToString:@"2"]) { NSLog(@"notification ID %@",[notification.userInfo valueForKey:@"ID"]); } ////// or ///// if ([notification.userInfo valueForKey:@"ID"] ) { NSLog(@"ID of notification %@",[notification.userInfo valueForKey:@"ID"]); }}
来自dIDFinishLaunchingWithOptions
- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // OverrIDe point for customization after application launch. if ([launchOptions objectForKey:UIApplicationLaunchOptionslocalnotificationKey]) { UIlocalnotification *notif=[launchOptions objectForKey:UIApplicationLaunchOptionslocalnotificationKey]; NSLog(@"notif.userInfo %@",notif.userInfo);// notif.userInfo {// ID = 2;// } } return YES;}总结
以上是内存溢出为你收集整理的ios – 从哪个UILocalNotification中检测到一个应用程序被打开全部内容,希望文章能够帮你解决ios – 从哪个UILocalNotification中检测到一个应用程序被打开所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)