如何从 iOS 应用通知设置重定向到应用通知设置
How to redirect from iOS app notifications settings to app notification settings
解释我想要实现的目标的最佳方式是使用 Facebook iOS 应用程序屏幕截图:
单击该按钮会将用户直接重定向到 Facebook 应用程序(通知设置)。
我只能将一些开关和标签添加到根设置 window(通过使用 Settings.bundle。
那么如何将用户从我的应用通知设置重定向到我的应用?
在此先感谢您的帮助。
您应该使用 UNUserNotificationCenter 并请求 .providesAppNotificationSettings
的授权
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound, .providesAppNotificationSettings])
然后使用UNUserNotificationCenterDelegate方法进行处理:
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
解释我想要实现的目标的最佳方式是使用 Facebook iOS 应用程序屏幕截图:
单击该按钮会将用户直接重定向到 Facebook 应用程序(通知设置)。
我只能将一些开关和标签添加到根设置 window(通过使用 Settings.bundle。
那么如何将用户从我的应用通知设置重定向到我的应用?
在此先感谢您的帮助。
您应该使用 UNUserNotificationCenter 并请求 .providesAppNotificationSettings
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound, .providesAppNotificationSettings])
然后使用UNUserNotificationCenterDelegate方法进行处理:
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