如何从iOS应用通知设置重定向到应用通知设置

时间:2018-12-21 00:19:55

标签: ios swift xcode info.plist root.plist

解释我想存档的最好方法是使用Facebook iOS应用屏幕截图:

Screenshot of Facebook iOS app

单击该按钮可将用户直接重定向到Facebook应用(通知设置)。

我只能向根设置窗口添加一些开关和标签(通过使用Settings.bundle。

那么如何将用户从我的应用通知设置重定向到我的应用?

在此先感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

您应该使用UNUserNotificationCenter并为.providesAppNotificationSettings请求授权

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

然后使用UNUserNotificationCenterDelegate方法进行处理:

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

迅速

@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