ios 为什么CloudKit通知没有到达时,应用程序是从试飞安装,而它的工作时,从Xcode编译?

8ehkhllq  于 2023-02-17  发布在  iOS
关注(0)|答案(2)|浏览(102)

CloudKit通知不会到达生产环境(AppStore、TestFlight),但可以在开发模式下工作(从Xcode安装)。
为什么?
以下是我注册远程通知的方式:

let center = UNUserNotificationCenter.current()
    
    center.delegate = self
    center.requestAuthorization(options: [.alert, .badge, .sound]) { authorised, error in
        
        DispatchQueue.main.sync {
            application.registerForRemoteNotifications()
        }
    }

这是我保存订阅的方式:

func subscribeForChanges() {
    
    let options: CKQuerySubscriptionOptions = [.firesOnRecordCreation, .firesOnRecordUpdate, .firesOnRecordDeletion]
    
    let serviceSubscription = CKQuerySubscription(recordType: "Service", predicate: NSPredicate(value: true), options: options)
    let goalSubscription = CKQuerySubscription(recordType: "Goal", predicate: NSPredicate(value: true), options: options)
    let territorySubscription = CKQuerySubscription(recordType: "Territory", predicate: NSPredicate(value: true), options: options)
    let addressSubscription = CKQuerySubscription(recordType: "Address", predicate: NSPredicate(value: true), options: options)
    let noteSubscription = CKQuerySubscription(recordType: "Note", predicate: NSPredicate(value: true), options: options)
    let daySubscription = CKQuerySubscription(recordType: "Day", predicate: NSPredicate(value: true), options: options)
    let shareSubscription = CKQuerySubscription(recordType: "cloudkit.share", predicate: NSPredicate(value: true), options: options)
    
    let notificationInfo = CKNotificationInfo()
    notificationInfo.shouldBadge = false
    notificationInfo.shouldSendContentAvailable = true
    
    serviceSubscription.notificationInfo = notificationInfo
    goalSubscription.notificationInfo = notificationInfo
    territorySubscription.notificationInfo = notificationInfo
    addressSubscription.notificationInfo = notificationInfo
    noteSubscription.notificationInfo = notificationInfo
    daySubscription.notificationInfo = notificationInfo
    shareSubscription.notificationInfo = notificationInfo
    
    let privateSubscriptionsOperation = CKModifySubscriptionsOperation(subscriptionsToSave: [serviceSubscription, goalSubscription, territorySubscription, addressSubscription, noteSubscription, daySubscription, shareSubscription], subscriptionIDsToDelete: nil)
    privateSubscriptionsOperation.database = CloudAssistant.shared.privateDatabase
    
    let notificationInfoDatabaseSubscription = CKNotificationInfo()
    notificationInfoDatabaseSubscription.shouldSendContentAvailable = true
    
    let subscription = CKDatabaseSubscription(subscriptionID: "pl.blue-world.fieldservice.sharedDatabase")
    subscription.notificationInfo = notificationInfoDatabaseSubscription
    let sharedSubscriptionsOperation = CKModifySubscriptionsOperation(subscriptionsToSave: [subscription], subscriptionIDsToDelete: nil)
    sharedSubscriptionsOperation.database = CloudAssistant.shared.sharedDatabase

    let queue = OperationQueue()
    queue.maxConcurrentOperationCount = 1
    queue.addOperation(privateSubscriptionsOperation)
    queue.addOperation(sharedSubscriptionsOperation)
    privateDatabase.save(CKRecordZone(zoneName: "fieldservice")) { _, _ in }
}
lg40wkob

lg40wkob1#

当类似的事情发生在我身上时,它是由于混淆了dev和prod环境之间的服务器更改令牌引起的。在我的情况下,dev更改令牌是,比如说aaabbb,而prod更改令牌是更早的,比如,aaaaab。由于我无意中使用了dev更改令牌,它“领先于”prod。
我看到你已经编辑了你的问题,但是我记得在以前的版本中,我相信你已经配置了xcode构建来使用prod env。但是,有一个简单的测试来证明或反驳这个理论是否与你的问题有关。在你没有接收到通知的env中应用init之后,调用
CKFetch通知更改操作
使用Nil作为服务器更改令牌。这应该会返回该用户从一开始的所有通知。如果结果中包含缺失的通知,则问题可能出在处理更改令牌的方式上。
否则,我将使用以下命令转储该用户的所有子对象
CKFetch订阅操作
在xcode构建和testflight构建中,比较这两个集合,密切注意 predicate 。我希望列表是相同的,因为您已经在使用prodenv,但是在寻找更复杂的原因之前,我会排除这个简单的测试。

rxztt3cl

rxztt3cl2#

静默推送通知在iOS 11.0.X中存在问题在iOS 11.1中有一个修复程序。
在开发模式下,您可能会收到通知,因为通常设备是通过电源线连接到计算机的。连接电源时会处理静默通知!
如果您的开发设备是iOS 11.0.X,这可能就是问题所在。

相关问题