Post

iOS 12 以上:Swift 实作APP通知设定页捷径|提升使用者通知体验

针对iOS 12以上用户,透过Swift新增APP通知设定捷径,让使用者可直接在APP内调整通知偏好,避免系统直接关闭通知导致错过重要讯息,提升推播精准度与使用者满意度。

iOS 12 以上:Swift 实作APP通知设定页捷径|提升使用者通知体验

Click here to view the English version of this article.

點擊這裡查看本文章正體中文版本。

基于 SEO 考量,本文标题与描述经 AI 调整,原始版本请参考内文。


iOS ≥ 12 在使用者的「设定」中增加「APP通知设定页」捷径 (Swift)

除了从系统关闭通知,让使用者还有其他选择

紧接著前三篇文章:

我们继续针对推播进行改进,不管是原有的技术或是新开放的功能,都来尝试尝试!

这次是啥?

iOS ≥ 12 可以在使用者的「设定」中增加您的APP通知设定页面捷径,让使用者想要调整通知时,能有其他选择;可以跳转到「APP内」而不是从「系统面」直接关闭,ㄧ样不啰唆先上图:

「设定」->「APP」->「通知」->「在APP中设定」

「设定」->「APP」->「通知」->「在APP中设定」

另外在使用者收到通知时,若欲使用3D Touch调整设定「关闭」通知,会多一个「在APP中设定」的选项供使用者选择

「通知」->「3D Touch」->「…」->「关闭…」->「在APP中设定」

「通知」->「3D Touch」->「…」->「关闭…」->「在APP中设定」

怎么实作?

这部分的实作非常简单,第一步仅需在要求推播权限时多要求一个 .providesAppNotificationSettings 权限即可

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
        
    }
}

在询问过使用者要不要允许通知之后,通知若为开启状态下方就会出现选项啰( 不论前面使用者按允许或不允许 )。

第二步:

第二步,也是最后一步;我们要让 appDelegate 遵守 UNUserNotificationCenterDelegate 代理并实作 userNotificationCenter( _ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) 方法即可!

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
    }
    //其他部份省略...
}
extension AppDelegate: UNUserNotificationCenterDelegate {
    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
        //跳转到你的设定页面位置..
        //EX:
        //let VC = SettingViewController();
        //self.window?.rootViewController.present(alertController, animated: true)
    }
}
  • 在Appdelegate的didFinishLaunchingWithOptions中实现代理

  • Appdelegate遵守代理并实作方法

完成!相较于前几篇文章,这个功能实作相较起来非常简单 🏆

总结

这个功能跟 前一篇 提到的先不用使用者授权就发干扰性较低的静音推播给使用者试试水温有点类似!

都是在开发者与使用者之前架起新的桥梁,以往APP太吵,我们会直接进到设定页无情地关闭所有通知,但这样对开发者来说,以后不管好的坏的有用的…任何通知都无法再发给使用者,使用者可能也因此错过重要消息或限定优惠.

这个功能让使用者欲关闭通知时能有进到APP调整通知的选择,开发者可以针对推播项目细分,让使用者决定自己想要收到什么类型的推播。

结婚吧APP 来说,使用者若觉得专栏通知太干扰,可个别关闭;但依然能收到重要系统消息通知.

p.s 个别关闭通知功能是我们APP本来就有的功能,但透过结合iOS ≥12的新通知特性能有更好的效果及使用者体验的提升

有任何问题及指教欢迎 与我联络


Buy me a beer

本文首次发表于 Medium (点击查看原始版本),由 ZMediumToMarkdown 提供自动转换与同步技术。

Improve this page on Github.

This post is licensed under CC BY 4.0 by the author.