Ban*_*iuk 23
如何实施 IOS 关键警报指南 [2021 年 7 月]
\n第一步
\n您需要在 Apple 网站上请求关键警报通知权利。
\n然后你需要等待苹果方面批准你的请求。他们会向您发送一封电子邮件。就我而言,我只等了三天。一些开发人员等待答案大约 1-4 周。
\n请求批准后您需要做什么?
\n打开developer.apple.com 上的“标识符”页面,然后选择要启用严重警报的应用程序的标识符。\n
在打开的页面上,单击 \xc2\xabAdditional features\xc2\xbb 并勾选 \xc2\xabCritical Alerts\xc2\xbb 框。然后单击\xc2\xabSave\xc2\xbb 按钮。\n
导航到“配置文件”页面,然后单击加号按钮注册新的配置配置文件。\n
选择 \xc2\xabiOS App Development\xc2\xbb 选项,然后单击 \xc2\xabContinue\xc2\xbb 按钮。\n
如何在 Xcode 中选择配置文件
\n打开您的 Xcode 项目。
\n选择您的目标。
\n选择\xc2\xab签名和功能\xc2\xbb。
\n取消选中\xc2\xab自动管理签名\xc2\xbb。
\n如何添加权利文件
\nmobiledev99的指南
\n




我们需要在代码中添加什么
\n请求授权
\nlet center = UNUserNotificationCenter.current()\ncenter.requestAuthorization(options: [.alert, .badge, .sound, .criticalAlert]) { (granted, error) in}\nRun Code Online (Sandbox Code Playgroud)\n对于本地通知
\n将您的声音更改UNMutableNotificationContent为下一个:
let notificationContent = UNMutableNotificationContent()\nnotificationContent.sound = UNNotificationSound.defaultCritical\nRun Code Online (Sandbox Code Playgroud)\n如果您想使用自定义声音,则需要将代码替换为以下代码:
\nlet notificationContent = UNMutableNotificationContent()\nnotificationContent.sound = UNNotificationSound.criticalSoundNamed(UNNotificationSoundName(rawValue:"YourCustomSound.mp3"))\nRun Code Online (Sandbox Code Playgroud)\n对于推送通知(来自 Tapcode 教程)
\n{ \n "aps":{ \n "alert": "This is a Critical Alert!",\n "badge": 1,\n "sound": { \n "critical": 1,\n "name": "your_custom_sound.aiff",\n "volume": 1.0\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n
有多种来源可以帮助您为 iOS 应用程序实现关键警报。我发现两个非常有帮助的:
\nhttps://www.tapcode.co/2018/10/17/how-to-implement-ritic-alerts-in-ios-12/
\nhttps://medium.com/@shashidharamsani/implementing-ios-ritic-alerts-7d82b4bb5026#:~:text=iOS%2012%20has%20the%20ritic,允许%20to %20send%20ritic %20alerts 。
\n两者都描述了请求 Apple 批准的必要条件以及如何更新项目以包含关键警报通知 \xe2\x80\x93,但有一个例外。这些文章介绍了如何更新您的权利文件以添加关键警报密钥。但是,当您的应用程序当前没有权利文件时,您该怎么办?\n经过一番研究,我得出了以下步骤,可以用作处理此困境的指南。\n当您到达以下部分时有关更新权利文件的文章请按以下步骤操作:
\n任务完成!
\n特里·柴森
\n