我正在我的iOS应用程序中实现iOS。实际上,在创建通知时,我有一个带有方法的实现:
-(void)setAlarmAction: (NSDate *) notificationDay days: (NSNumber *) day alert : (NSNumber * ) priority name:(NSString * ) nameNotification {
NSDate *notificationDate = notificationDay;
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil) {
return;
}
localNotification.fireDate = notificationDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = [NSString stringWithFormat: @"Quedan %@ dias" , day];
localNotification.alertAction = @"Ver Documento";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber]+1; //aumenta en uno el numero de notificaciones
////////////
NSDictionary *infoDictionary = [NSDictionary dictionaryWithObject:@"notification" forKey:nameNotification]; //1º que se guarda , 2º con que clave
localNotification.userInfo = infoDictionary;
////////////
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:localNotification];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:nameNotification];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
// Get list of local notifications
NSArray *localNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
for( UILocalNotification * local in localNotifications) {
NSLog(@"Notificacion: %@ fecha :%@",local.alertBody,local.fireDate.description);
}
}
-(void) launchNotificacion:(Documento *)document {
self.txDate.text = document.text;
}我希望应用程序在后台中运行,当它出现在tabBar上时,我可以将它推送到一个具体的视图中,并启动一些数据。我是在didFinishlaunchingWithOptions做的。
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//self.viewDocumentForm
VTDocumentFormViewController *VTDocument = [[VTDocumentFormViewController alloc] initWithNibName:@"VTDocumentFormViewController" bundle:nil];
UILocalNotification *notification = [launchOptions objectForKey:
UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
[self.window.rootViewController presentViewController: VTDocument animated:YES completion:nil];
Documento *reminderDocument = [NSEntityDescription insertNewObjectForEntityForName:@"Documento" inManagedObjectContext:self.managedObjectContext];
reminderDocument = [notification.userInfo objectForKey: key ];
[self.viewDocumentForm launchNotificacion:reminderDocument];
application.applicationIconBadgeNumber = notification.applicationIconBadgeNumber-1;
}
// Override point for customization after application launch.
return YES;
}但这不管用,我也不知道原因。拜托救救我。
发布于 2015-02-24 16:15:07
只有当app在到达didFinishLaunchingWithOptions:之前被挂起/终止时,launchOptions中的UIApplicationLaunchOptionsLocalNotificationKey才会被调用。
如果你的应用程序只是在后台(而不是被杀死)或活动,你会被application:didReceiveLocalNotification:炒掉
另外,在您的didFinishLaunchingWithOptions:中,我看不到您在哪里注册了用户通知设置(用于iOS8)…小象:
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge;
UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
}https://stackoverflow.com/questions/22009920
复制相似问题