Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect from iOS app notifications settings to app notification settings

The best way to explain what I want to archieve is by using Facebook iOS app screenshot:

Screenshot of Facebook iOS app

Clicking that button redirects user directly to Facebook app (notifications settings).

I am only able to add some switches and labels to root settings window (by using Settings.bundle.

So how can I redirects user from my app notifications settings to my app?

Thanks in advance for every help.

like image 638
Boomerange Avatar asked Dec 21 '18 00:12

Boomerange


1 Answers

You should use UNUserNotificationCenter and request authorization for .providesAppNotificationSettings

UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound, .providesAppNotificationSettings])

Then use UNUserNotificationCenterDelegate method for handling:

func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
    // Open settings view controller
}

Swift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        UNUserNotificationCenter.current().delegate = self
        UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound, .providesAppNotificationSettings])
        return true
    }

    func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
        // Open settings view controller
    }
}

Objective-C

@interface TAXAppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
    ////
@end

@implementation TAXAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
    [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionProvidesAppNotificationSettings) completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (granted) {
            ///
        }
    }];

    return YES;
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification
{
    // Open settings view controller 
}

@end
like image 77
Genja Grishin Avatar answered Sep 19 '22 23:09

Genja Grishin