【问题标题】:How to redirect from iOS app notifications settings to app notification settings如何从 iOS 应用通知设置重定向到应用通知设置
【发布时间】:2019-05-21 12:13:36
【问题描述】:

解释我想要归档的最佳方式是使用 Facebook iOS 应用截图:

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

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

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

提前感谢您的每一个帮助。

【问题讨论】:

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


    【解决方案1】:

    您应该使用 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
        }
    }
    

    目标-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
    

    【讨论】:

    • 请注意,如果您在更改此设置之前已经申请了访问权限,则需要重新申请。如果“设置”应用在添加该选项之前已经打开,请强制退出并重新启动以显示按钮。
    猜你喜欢
    • 1970-01-01
    • 2016-01-29
    • 1970-01-01
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    • 2017-08-08
    相关资源
    最近更新 更多