UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

CloudKit development vs. production

Forums > iOS

Hi, I'm building a CloudKit backed app, that uses CKDatabaseSubscriptions and CKQuerySubscriptions to keep track of changes in the db. I'm also storing a Bool in UserDefaults to set whether the user is already subscribed, to prevent getting 'Rate Limited'. This work very well for my local testers (my family :-) ).

Now enter TestFlight...

Using a build from TestFlight, enables production database use. However, all my local users have already subscribed to changes, as indicated by the Bool in UserDefaults.

My question: how to deal with this situation? Can I read in Swift whether the app is currently connected to the production vs. development database? If not, should I just delete and resubscribe with every run on either development or production, depending on the build (seems wasteful)?

3      

Hi what about just checking for existence of subscription?

Also would you be willing to offer me a few pointers about subscriptions setup? I am working on a CloudKit app myself and need to monitor changes to the database in order to update data. I did not manage to find many tutorials online. Thanks

3      

hi, thanks, I should thought of that before as I'm actually already doing that somewhere else in the app...

What specific subscription code are you looking for?

3      

I have Apple TV app where I would like to monitor CloudKit private database for new CKEntities of particular type and then download them. I think I need the CKDatabaseSubscription right? But I did not manage to find any clear examples for current Swift.

3      

Does this help?

func createDatabaseSubscriptionOperationIn(_ database: CKDatabase, with subscriptionId: String, for recordType: CKRecord.RecordType) -> CKModifySubscriptionsOperation {
        let subscription = CKDatabaseSubscription.init(subscriptionID: subscriptionId)
        subscription.recordType = recordType

        let notificationInfo = CKSubscription.NotificationInfo()
        notificationInfo.shouldSendContentAvailable = true

        subscription.notificationInfo = notificationInfo

        let operation = CKModifySubscriptionsOperation(subscriptionsToSave: [subscription], subscriptionIDsToDelete: [])

        operation.qualityOfService = .userInitiated
        operation.database = database
        return operation
    }

3      

Thanks. Do you have any tips how to debug this? I should have everything set up for the subscription to fire but I am not getting the remote notification.

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.