iOS:当您没有权利文件时,您如何为您的应用程序实施关键警报?

如何解决iOS:当您没有权利文件时,您如何为您的应用程序实施关键警报?

如果您还没有权利文件,您会怎么做?

解决方法

有多种来源可以帮助您为 iOS 应用实施关键警报。我发现两个非常有帮助:

https://www.tapcode.co/2018/10/17/how-to-implement-critical-alerts-in-ios-12/

https://medium.com/@shashidharyamsani/implementing-ios-critical-alerts-7d82b4bb5026#:~:text=iOS%2012%20has%20the%20critical,allowed%20to%20send%20critical%20alerts

两者都描述了请求 Apple 批准的必要条件,以及如何更新您的项目以包含关键警报通知——只有一个例外。这些文章解释了如何更新您的权利文件以添加关键警报键。但是,当您的应用程序当前没有权利文件时,您会怎么做? 经过一番研究,我得出了以下步骤,可用作处理此困境的指南。 当您阅读解决更新权利文件的部分文章时,请按以下步骤操作:

  1. 在“功能”选项卡下,单击 +(加号)以添加功能(我选择了钥匙串共享)。这将导致 Xcode 生成一个 .entitlements 文件(克服了主要障碍)。
  2. 在项目导航器中单击该文件以将其打开。如果权利文件旁边的显示三角形处于打开状态,您将看到所选功能的密钥(钥匙串共享)。如果显示三角形未打开,请单击以将其打开。
  3. 单击权利文件旁边的 +(加号)以添加权利。将出现一个包含选项的下拉菜单,但您必须键入关键警报通知的键才能手动输入。
  4. 输入文章中关键警报通知的密钥: com.apple.developer.usernotifications.critical-alerts
  5. 将类型更改为布尔值并选择 YES 作为值。
  6. 单击您在步骤 1(钥匙串共享)中用于创建权利文件的功能旁边的 –(破折号)以将其删除。您现在拥有一个包含您需要的关键警报密钥的权利文件。
  7. 构建并运行您的应用,您应该会看到要求用户允许关键警报的提示。

任务完成!

特里·柴森

,

IOS 关键警报实施指南 [2021 年 7 月]

第一步

  1. 您需要在 Apple 网站上request获得重要警报通知权利。

  2. 然后你需要等待苹果方面批准你的请求。他们会给你发一封电子邮件。就我而言,我只等了 3 天。一些开发者等待了大约 1-4 周的答复。

请求获得批准后您需要做什么?

  1. 打开 developer.apple.com 上的 Identifiers 页面,然后选择您要在其中启用严重警报的应用程序的标识符。 enter image description here

  2. 在打开的页面上,单击“附加功能”并勾选“关键警报”框。然后点击«保存»按钮。 enter image description here

  3. 导航到 Profile page 并单击加号按钮以注册新的配置文件。 enter image description here

  4. 选择«iOS App Development»选项并点击«Continue»按钮。 enter image description here

  5. 选择您的应用程序 ID,然后单击“继续”按钮。 enter image description here

  6. 选择所有证书并单击«继续»按钮。 enter image description here

  7. 选择您的设备并点击«继续»按钮。 enter image description here

  8. 输入您的配置文件的名称,然后单击生成按钮。例如,名称可以是您的应用程序名称。 enter image description here

  9. 您的配置文件已准备就绪。单击下载按钮。然后双击以下文件以安装您的配置文件。 enter image description here

如何在 Xcode 中选择您的配置文件

  1. 打开您的 Xcode 项目。

  2. 选择您的目标。

  3. 选择“签名和功能”。

  4. 取消选中“自动管理签名”。

  5. 配置文件字段中,选择您在前面的步骤中下载并安装的配置文件enter image description here

  6. 检查权利。 enter image description here

如何添加授权文件

mobiledev99 指导

  1. 单击加号以添加功能。 enter image description here
  2. 选择“钥匙串共享” enter image description here
  3. 打开 .entitlements 文件。将光标悬停在“权利文件”字段并单击加号按钮。 enter image description here
  4. 将值键名称更改为«com.apple.developer.usernotifications.critical-alerts», 类型为«Boolean»,值为«1»。 enter image description here
  5. 然后将光标悬停在“钥匙串访问组”字段并单击减号按钮。 enter image description here

我们需要在代码中添加什么

请求授权

let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert,.badge,.sound,.criticalAlert]) { (granted,error) in}

对于本地通知

将您的 UNMutableNotificationContent 声音更改为下一个:

let notificationContent = UNMutableNotificationContent()
notificationContent.sound = UNNotificationSound.defaultCritical

如果你想使用你的自定义声音,你需要用这个替换代码:

let notificationContent = UNMutableNotificationContent()
notificationContent.sound = UNNotificationSound.criticalSoundNamed(UNNotificationSoundName(rawValue:"YourCustomSound.mp3"))

推送通知(来自 Tapcode 教程)

{  
   "aps":{  
       "alert": "This is a Critical Alert!","badge": 1,"sound": {  
         "critical": 1,"name": "your_custom_sound.aiff","volume": 1.0
        }
     }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-