Add ‘App Notification Settings Page’ Shortcut in User’s ‘Settings’ on iOS ≥ 12 (Swift)
Besides turning off notifications from the system, give users other options
Following the previous three articles:
- iOS ≥ 10 Notification Service Extension Application (Swift)
- What? iOS 12 Can Send Push Notifications Without User Authorization (Swift)
- Handling Push Notification Permission Status from iOS 9 to iOS 12 (Swift)
We continue to improve push notifications, whether it’s existing technology or newly available features, let’s give them a try!
What’s this time?
iOS ≥ 12 allows you to add a shortcut to your app’s notification settings page in the user’s “Settings,” giving users other options when they want to adjust notifications; they can jump to “in-app” instead of turning off notifications directly from the “system.” Here’s a preview:
Settings -> App -> Notifications -> In-App Settings
Additionally, when users receive notifications and want to use 3D Touch to adjust settings to “turn off” notifications, there will be an extra “In-App Settings” option for users to choose from.
Notifications -> 3D Touch -> … -> Turn Off… -> In-App Settings
How to implement?
The implementation is very simple. The first step is to request an additional .providesAppNotificationSettings permission when requesting push notification permissions.
1
2
3
4
5
6
7
8
//appDelegate.swift didFinishLaunchingWithOptions or....
if #available(iOS 12.0, *) {
let center = UNUserNotificationCenter.current()
let permissiones:UNAuthorizationOptions = [.badge, .alert, .sound, .provisional,.providesAppNotificationSettings]
center.requestAuthorization(options: permissiones) { (granted, error) in
}
}
After asking the user whether to allow notifications, if notifications are enabled, an option will appear below ( regardless of whether the user previously allowed or disallowed notifications ).
Step Two:
The second step, and the final step; we need to make appDelegate conform to the UNUserNotificationCenterDelegate protocol and implement the userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) method!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//appDelegate.swift
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
}
return true
}
//Other parts omitted...
}
extension AppDelegate: UNUserNotificationCenterDelegate {
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
//Navigate to your settings page..
//EX:
//let VC = SettingViewController();
//self.window?.rootViewController.present(alertController, animated: true)
}
}
- Implement the delegate in AppDelegate’s didFinishLaunchingWithOptions
- AppDelegate conforms to the delegate and implements the method
Completed! Compared to the previous articles, this feature implementation is very simple 🏆
Summary
This feature is somewhat similar to the one mentioned in the previous article, where we send low-interference silent push notifications to users without requiring their authorization to test the waters!
Both features aim to build a new bridge between developers and users. In the past, if an app was too noisy, we would mercilessly go to the settings page and turn off all notifications. However, this means that developers can no longer send any notifications, whether good or bad, useful or not, to the users. Consequently, users might miss important messages or exclusive offers.
This feature allows users to have the option to adjust notifications within the app when they want to turn them off. Developers can segment push notification items, allowing users to decide what type of push notifications they want to receive.
For the Wedding App, if users find the column notifications too intrusive, they can turn them off individually; but they can still receive important system messages.
p.s. The individual notification toggle feature is something our app already had, but by combining it with the new notification features in iOS ≥12, we can achieve better results and improve user experience.
If you have any questions or feedback, feel free to contact me.
===
===
This article was first published in Traditional Chinese on Medium ➡️ View Here