【发布时间】:2020-11-04 12:52:54
【问题描述】:
我对“正常”推送通知与远程通知之间的区别以及我的免费配置文件可以实现哪些区别感到有些困惑。
我可以使用以下代码发送出现在锁定屏幕上的推送通知:
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool {
...
registerForPushNotifications()
createNotification()
return true
}
func registerForPushNotifications() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { [weak self] granted, _ in
print("Permission granted: \(granted)")
guard granted else { return }
}
}
static func createNotification() {
let content = UNMutableNotificationContent()
content.title = "test-title"
// 2. create trigger
var components = DateComponents.init()
components.hour = 14
components.minute = 39
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: false)
content.badge = 1
content.sound = UNNotificationSound.default
// 4. create send request
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
// add request to send center
UNUserNotificationCenter.current().add(request) { error in
if error == nil {
print("Time Interval Notification scheduled!")
}
}
}
但是,我真正想要的是创建一个基于某些 HTTP 请求的每日通知。
换句话说,我想向某个 API 发送一个 HTTP 请求(比如它返回一个布尔值)并根据该值创建一个通知。
我做了一些研究,我认为远程通知能够做到这一点。
不幸的是,当我尝试注册远程通知时:
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
我收到一个错误:没有为应用程序找到有效的“aps-environment”权利字符串。
正如我所说 - 我没有付费的 Apple 开发者会员资格。
我的问题是:
- 远程通知真的能满足我的需求吗?
- 是否可以使用免费配置帐户进行远程通知?
我发现“普通”推送通知确实是可能的。
谢谢!
【问题讨论】:
标签: ios swift push-notification apple-push-notifications provisioning-profile