対話型通知を作成しました。対話型通知には、スヌーズとディスミュートの2つのアクションがあります。 通知が発生し、私は2つのアクションを得ました。それをタップすると、メソッドを呼び出します:対話型通知は、対処後にアプリケーションを開きません。
-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
ただし、完了後、アプリは開きません。スヌーズボタンをタップしてviewcontrollerを開きたいが、didFinishLaunchingWithOptionsもdidReceiveLocalNotificationも呼び出さない。私を案内してください。チュートリアルでは、このアクションが実行されたログだけを持っています。ひどく立ち往生した。
-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
{
recentLocalnotification = notification;
application.applicationIconBadgeNumber = 0;
if ([identifier isEqualToString:kNotificationActionSnooze]) {
strTappedButtonFromNotification = kNotificationActionSnooze ;
[self GetTopViewController];
// UIStoryboard *storyboard = [CommonMethods getiPhoneOriPadStoryboard];
// UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
//
// SnoozeViewController *snooze = [storyboard instantiateViewControllerWithIdentifier:kSnoozeViewController];
// snooze.dictNotificationData = recentLocalnotification.userInfo;
// [navController pushViewController:snooze animated:YES];
//
// [self applicationDidBecomeActive:[UIApplication sharedApplication]];
}
else if ([identifier isEqualToString:kNotificationActionDismiss]) {
strTappedButtonFromNotification = kNotificationActionDismiss;
NSLog(@"Notification Dismissed");
}
else{
strTappedButtonFromNotification = @"";
}
completionHandler();
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication]cancelAllLocalNotifications];
application.applicationIconBadgeNumber = 0;
UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (locationNotification) {
application.applicationIconBadgeNumber = 0;
}
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:@"SNOOZE"];
[action1 setIdentifier:kNotificationActionSnooze];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];
[action2 setTitle:@"DISMISS"];
[action2 setIdentifier:kNotificationActionDismiss];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:kNotificationCategoryIdent];
[actionCategory setActions:@[action1, action2]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
return YES;
}
このコメント付きコードでは、決して開いていないコントローラーを開こうとしています。
ですでにだ場合を除き、バックグラウンドでアプリケーションを起動前景? UIMutableUserNotificationActionの使い方を私に見せてもらえますか? –
アプリが背景にあります –
UIMutableUserNotificationActionコード? –