我已創建在此模式下本地通知:在午餐UILocalNotification iOS8上handleActionWithIdentifier從來沒有所謂
AppDelegate.m
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
// Setup each action thar will appear in the notification
UIMutableUserNotificationAction *acceptAction = [[UIMutableUserNotificationAction alloc] init];
acceptAction.identifier = @"ACCEPT_ACTION"; // Identifier is returned in handleActionWithIdentifier: after the user taps on an action
acceptAction.title = @"ACCEPT_TITLE";
acceptAction.activationMode = UIUserNotificationActivationModeForeground; //Brings the app into the foreground when action tapped
UIMutableUserNotificationCategory *not_cat = [[UIMutableUserNotificationCategory alloc] init];
not_cat.identifier = @"testCategory";
[not_cat setActions:@[acceptAction] forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObjects:not_cat, nil];
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
然後創建一個本地通知:
+ (void)sendLocalNotification:(NotificaObject*)n
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
// Set the category to the category that contains our action
localNotif.category = @"testCategory";
localNotif.alertBody = @"First Test mex, no action";//n.titolo;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
localNotif.userInfo = [NSDictionary dictionaryWithObject:@"0" forKey:@"id"];
localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:5]; //5 seconds
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
NSLog(@"Sending Local notification");
}
通知時FIRE如果應用程序(iOS8)在AppDelegate中是FOREGROUND 則稱爲
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
而且從不叫
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
如果應用程序(iOS 8)是在後臺只調用didReceiveLocalNotification
我想不通爲什麼handleActionWithIdentifier永遠不會調用
我用xcode6 .01和爲ios7/8開發,我做錯了什麼?
當你選擇喜歡點擊按鈕,通知一些動作這將調用...請訪問此鏈接... https://開頭的github的.com/sgup77/SGNotification – 2014-10-14 11:41:50