我正在嘗試安排交互式UILocalNotifaction
。Schedule Interactive UILocalNotification - Obj-C
我的嘗試是使用下面的代碼,這是我從這個tutorial抓起:
NSString * const NotificationCategoryIdent = @"ACTIONABLE";
NSString * const NotificationActionOneIdent = @"ACTION_ONE";
NSString * const NotificationActionTwoIdent = @"ACTION_TWO";
- (void)registerForNotification {
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:@"Action 1"];
[action1 setIdentifier:NotificationActionOneIdent];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];
[action2 setTitle:@"Action 2"];
[action2 setIdentifier:NotificationActionTwoIdent];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:NotificationCategoryIdent];
[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];
}
然而,這段代碼似乎並沒有真正的任何地方安排的通知。我錯過了什麼?
你有沒有implemen t應用程序:handleActionWithIdentifier:forLocalNotification:completionHandler:'你的應用程序委託中的方法? – soulshined 2015-01-20 19:01:47
@soulshined我的意思是不,但不應該對通知的安排有任何影響... – Apollo 2015-01-21 03:13:23
你仍然必須像任何其他通知一樣安排本地通知。在這裏,您只需註冊該類型的通知即屬於一個類別。 – soulshined 2015-01-21 03:15:30