Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

ios - CloudKit push notifications on record update stopped working

EDIT: Retested today 27.08.2015 and it works again, Apple has fixed it.

I have an application in development mode. The application uses CKSubscription to get notified on changes on the server, configured for all three options: create, update, delete. Everything was working fine but recently during regression tests I have discovered the application does not receive notifications on record updates, the create and delete notifications are still working. The susbcription types are set correctly for all three options as I checked on the dashboard and the application is registered for CKSubscription as it was a couple of days ago when it was working like charm. I am not getting any errors from CloudKit. The reset of development environment did not help. I have re-tested with the version with which I am sure it was working and got the same results.

Any idea what might be causing this issue, what else should I check / try?

Additional Info: I guess something might go wrong at the server side. I have not changed anything in the code where I am subscribing for CloudKit events and handling push notifications - anyway also the version where it was working is not getting update notifications any longer. The application I am working on is published, thus changing container is no go. Not sure if this might be causing the issue, just want to mention: the app is using the same container for storing the Core Data in the cloud - the goal of the app upgrade is to migrate data to the CloudKit and use it as the cloud storage exclusively. It is confusing that everything was working fine for weeks and suddenly stopped working without any clear reason, probably as the effect of the load by intensive testing, adding record types...

Test with app developed from scratch: I have written a simple test app to check receiving notifications. I can receive only the notification on record creation. What is wrong with my code:

import UIKit
import CloudKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

let container = CKContainer.defaultContainer()

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    let settings = UIUserNotificationSettings(forTypes: .Alert, categories: nil)
    application.registerUserNotificationSettings(settings)
    application.registerForRemoteNotifications()

    return true
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
    println("didFailToRegisterForRemoteNotificationsWithError: (error)")
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    println("didRegisterForRemoteNotificationsWithDeviceToken: (deviceToken)")
    subscribe()
}

func subscribe() {
//        let predicate = NSPredicate(format: "text != %@", argumentArray: [""])
//        let predicate = NSPredicate(format: "TRUEPREDICATE", argumentArray: nil)
    let predicate = NSPredicate(value: true)
    let subscription = CKSubscription(recordType: "Note", predicate: predicate, options: .FiresOnRecordDeletion | .FiresOnRecordUpdate | .FiresOnRecordCreation)
    let notificationInfo = CKNotificationInfo()
    notificationInfo.alertBody = ""
    subscription.notificationInfo = notificationInfo
    let publicDatabase = container.publicCloudDatabase
    println("subscribing with CloudKit...")
    publicDatabase.saveSubscription(subscription, completionHandler: { (returnedSubscription, error) -> Void in
        if let error = error {
            println("subscription error (error.localizedDescription)")
        } else {
            println("subscription ok")
        }
    })
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    let ckNotification = CKQueryNotification(fromRemoteNotificationDictionary: userInfo)
    println("didReceiveRemoteNotification: (ckNotification)")
}

func applicationWillResignActive(application: UIApplication) {}

func applicationDidEnterBackground(application: UIApplication) {}

func applicationWillEnterForeground(application: UIApplication) {}

func applicationDidBecomeActive(application: UIApplication) {}

func applicationWillTerminate(application: UIApplication) {}

}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have experienced this behavior in the past. In my case I could solve it by just deleting the subscription and creating it again. You should do that from code and not the dashboard. Doing it from the dashboard only works for the account that you are loged in into the dashboard.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...