Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) {}

}

like image 798
Lubos Ilcik Avatar asked Jun 29 '15 05:06

Lubos Ilcik


People also ask

Why are my push notifications not working iPhone?

You can fix an iPhone that's not getting notifications by restarting it or making sure notifications are turned on. You should also make sure your iPhone is connected to the internet so apps can receive notifications. If all else fails, you should try resetting the iPhone — just make sure to back it up first.

How do I re enable push notifications?

From the “Settings” menu, tap “Notifications”. From here, find the app you wish to receive push notifications for. From here, tap “Allow Notifications” and then choose your options for how you wish to receive push notifications: a.

Do push notifications work when app is closed iOS?

Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.


1 Answers

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.

like image 165
Edwin Vermeer Avatar answered Oct 02 '22 21:10

Edwin Vermeer