【发布时间】:2014-10-02 11:38:06
【问题描述】:
我已经在这种模式下创建了一个本地通知:
午餐中的 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");
}
当应用程序 (iOS8) 为 FOREGROUND 时通知 FIRE 在 AppDelegate 中被调用
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
永远不要打电话
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
如果应用程序 (iOS8) 在后台仅调用 didReceiveLocalNotification
我不明白为什么 handleActionWithIdentifier 从不调用
我使用 xcode6.01 并为 ios7/8 开发,我做错了什么?
【问题讨论】:
-
当您在通知上选择一些操作(例如单击按钮)时,将调用它...请参阅此链接...github.com/sgup77/SGNotification
标签: ios objective-c xcode ios8 uilocalnotification