iOS: Push notification not showing dictionary info in iOS 10
Asked Answered
M

1

9

I am working on push notification in XCode 8 Beta, iOS 10 Version. I have got push notification received on device. When I clicked on notification, it fired delegate of UNUserNotificationCenterDelegate, app is opened, but it didn't show any response in userinfo. Do I need to change parameter for sending push in iOS 10 on server side. Below is my code.

    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
    [application registerUserNotificationSettings:settings];

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (!error) {
            NSLog(@"request authorization succeeded!");
        }
    }];


- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {

    NSLog(@"Notification is triggered");
    completionHandler(UNNotificationPresentationOptionAlert);
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {

    NSLog(@"Tapped in notification");
    NSLog(@"%@",response.notification);
    NSString *actionIdentifier = response.actionIdentifier;

    if ([actionIdentifier isEqualToString:@"com.apple.UNNotificationDefaultActionIdentifier"] ||
        [actionIdentifier isEqualToString:@"com.apple.UNNotificationDismissActionIdentifier"]) {
        return;
    }
}

In iOS 9,

aps =     {
    alert = "Multi extra param push.";
    badge = 0;
    sound = default;
};
t = I;
url = "http://www.google.com";

and in iOS 10

alert = "Multi extra param push.";
badge = 0;
sound = default;
Methodism answered 29/8, 2016 at 10:22 Comment(5)
why are you using beta iOS version ?Shaven
try this NSLog(@"%@",[response.notification.request.content.userInfo objectForKey:@"aps"]);Birdella
In iOS 9 aps = { alert = "Multi extra param push."; badge = 0; sound = default; }; t = I; url = "google.com"; In iOS 10 alert = "Multi extra param push."; badge = 0; sound = default;Methodism
I am not getting url and t value in iOS 10, is there any way to retrieve or do I need to change any thing.Methodism
I got the solution how to do, thanks for all the helpMethodism
F
32
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
    NSLog(@"%@", notification.request.content.userInfo);
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void(^)())completionHandler {
    NSLog(@"%@", response.notification.request.content.userInfo);
}
Fiddling answered 29/8, 2016 at 19:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.