Friday, 1 September 2017

Notification with Sound When App is in Foreground

Hello Friends, Normally APNS sends notification when app is in foreground with notification , badge and Alert. But When App is in foreground it only delivers notification but not with the sound feature.

For This Add this code in your AppDelegate.m method

- (void)userNotificationCenter:(UNUserNotificationCenter* )center willPresentNotification:(UNNotification* )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
    
    //For notification Banner - when app in foreground
    
    completionHandler(UNNotificationPresentationOptionAlert |  UNNotificationPresentationOptionSound |UNNotificationPresentationOptionBadge);
    
    // Print Notification info
    NSLog(@"Userinfo %@",notification.request.content.userInfo);

}


Thanks

No comments:

Post a Comment

Dependency Manager in iOS

What is Dependency Management? When working in iOS, there are plenty of amazing third party libraries that we can use to save us time an...