1
我已爲我的警報項目創建了推送本地通知。實施接收推送通知操作的代理
問題是,當我點擊一個動作按鈕(貪睡和好吧)我實現的委託沒有被調用。
這裏是我的推本地通知代碼:
UIMutableUserNotificationAction *notificationAction1 = [[UIMutableUserNotificationAction alloc] init];
notificationAction1.identifier = Snooze;
notificationAction1.title = @"Snooze";
notificationAction1.activationMode = UIUserNotificationActivationModeBackground;
notificationAction1.destructive = NO;
notificationAction1.authenticationRequired = NO;
UIMutableUserNotificationAction *notificationAction2 = [[UIMutableUserNotificationAction alloc] init];
notificationAction2.identifier = Okay;
notificationAction2.title = @"Okay";
notificationAction2.activationMode = UIUserNotificationActivationModeBackground;
notificationAction2.destructive = NO;
notificationAction2.authenticationRequired = NO;
UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init];
notificationCategory.identifier = @"Alarm";
[notificationCategory setActions:@[notificationAction1,notificationAction2] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:@[notificationAction1,notificationAction2] forContext:UIUserNotificationActionContextMinimal];
NSSet *categories = [NSSet setWithObjects:notificationCategory, nil];
這裏是實現委託代碼:
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler {
if ([identifier isEqualToString:Snooze]) {
NSLog(@"You chose Snooze");
}
else if ([identifier isEqualToString:Okay]) {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSLog(@"You chose Okay");
}
if (completionHandler) {
completionHandler();
}
}
我還不知道如何讓貪睡和好按鈕工作,所以我只是登錄一些東西,但沒有記錄時,我點擊貪睡/好吧。我錯過了什麼嗎?
我遵循的步驟,沒有錯誤,並運行,但仍然被點擊按鈕的動作時,不記錄。 – theFool