【问题标题】:Are remote notifications possible for free provisioning account?免费配置帐户是否可以进行远程通知?
【发布时间】: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 开发者会员资格。

我的问题是:

  1. 远程通知真的能满足我的需求吗?
  2. 是否可以使用免费配置帐户进行远程通知?

我发现“普通”推送通知确实是可能的。

谢谢!

【问题讨论】:

    标签: ios swift push-notification apple-push-notifications provisioning-profile


    【解决方案1】:
    1. 您似乎对远程推送通知的工作方式存在误解。您的服务器需要安排远程通知,而不是您的应用程序。您可以在服务器上安排每日远程通知,这应该可以满足您的需求,但正如我所说,您需要服务器端逻辑来实现这一点。

    2. 否 - 您需要付费的开发者会员才能使用远程推送通知。本地通知不需要付费会员,但远程通知需要。

    【讨论】:

    • 我明白了,谢谢。所以基本上 - 我需要为开发者会员支付费用,然后我才能使用远程推送通知(又名 UIApplication.shared.registerForRemoteNotifications() 将正常运行),对吗?
    • @UriYakir 完全正确
    • 完美。最后一个问题;你说我的服务器安排了远程通知。是否可以区分每个用户收到的远程通知?假设我的服务器有一个供应商 UUID 列表,应该接收通知 A,而其他应该接收通知 B。能做到吗?
    • @UriYakir 当然,每当应用注册远程通知时,您都会收到该用户的标识符,您可以使用该标识符来确定是否应将某些通知发送给该用户
    猜你喜欢
    • 1970-01-01
    • 2012-09-06
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多