代码之家  ›  专栏  ›  技术社区  ›  Boomerange weltan

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

  •  4
  • Boomerange weltan  · 技术社区  · 6 年前

    解释我想要归档的最好方法是使用Facebook iOS应用程序截图:

    Screenshot of Facebook iOS app

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

    谢谢你的帮助。

    0 回复  |  直到 6 年前
        1
  •  4
  •   Genja Grishin    5 年前

    .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