UILocalNotification iOS8 handleActionWithIdentifier never called

I created a local notification in this mode:

AppDelegate.m at lunch time

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)];
    }

then I create a local notification:

+ (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");
}

When FIRE is notified, if the application (iOS8) has a FOREGROUND value in AppDelegate, it is called

 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

and NEVER call

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler

if the application (iOS8) is in the background, only didReceiveLocalNotification call

I can't understand why handleActionWithIdentifier never calls

I am using xcode6.01 and developing for ios7 / 8, what am I doing wrong?

+4
source share
3 answers

. , . , , .

+1

dispatch_get_main_queue?

: handleActionWithIdentifier: forLocalNotification: completeHandler:

dispatch_async(dispatch_get_main_queue(), ^{
    while (YES) {
        [NSThread sleepForTimeInterval:1.0];
    }
});

dispatch_get_global_queue

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    while (YES) {
        [NSThread sleepForTimeInterval:1.0];
    }
});
0

:

1.- AppDelegate, didFinishLaunchingWithOptions , :

if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:")))
    {
        application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Sound | .Alert | .Badge, categories: nil))
    }

2.- nofications ( , ):

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void) {
    println("notification is here. Open alert window or whatever")
    // Must be called when finished
    completionHandler()
}

3.- :

 var localNotification: UILocalNotification = UILocalNotification()
    localNotification.alertAction = "Your Alarm!"
    localNotification.alertBody = "Your description"
    localNotification.fireDate = NSDate(timeIntervalSinceNow: 10) // your time
    localNotification.soundName = UILocalNotificationDefaultSoundName 
    // there are more and different options
    UIApplication.sharedApplication().scheduleLocalNotification(localNotification)

ios 8.3 swift 1.2

0

All Articles