Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

CloudKit User Push Notifications

I have an app that allows one user to invite another user to view a record by their email address. When this record is created I would like to send the inited user a push notification to notify them that they are invited to view it. How should I do this? The code below is what I am using to create the record with the user's email address.

Thanks

var users:[CKDiscoveredUserInfo]!
        var currentUser = ""
        var sharedUser = ""
        container.fetchUserRecordIDWithCompletionHandler { (theCurrentUser, error) -> Void in
            currentUser = theCurrentUser!.recordName
            print("User: \(theCurrentUser!.recordName)")
                       self.container.discoverAllContactUserInfosWithCompletionHandler({ (retrieverUsers, error) -> Void in

            self.container.discoverUserInfoWithEmailAddress("email@icloud.com", completionHandler: { (discoveredUser, error) -> Void in
                if error == nil {
                sharedUser = discoveredUser!.userRecordID!.recordName
                    print(sharedUser)
                } else {
                    print("Error")
                }
            })

            var userArray = [currentUser,sharedUser]

            let myRecord = CKRecord(recordType: "MyRecords")
            myRecord.setObject("this is one", forKey: "one")
            myRecord.setObject("this is two", forKey: "two")
            myRecord.setObject(currentUser, forKey: "currentUser")
            myRecord.setObject(userArray, forKey: "userAccess")

            self.publicDB!.saveRecord(myRecord, completionHandler:
                ({returnRecord, error in
                    if let err = error {
                    } else {
                        dispatch_async(dispatch_get_main_queue()) {
                        }
                    }
                }))


        }

1 Answer

I don't think CloudKit allows server side code.

Do consider using Parse.com or firebase for something like this, or roll your own Servers(it's super fun!!)

Source(someone had a similar problem): http://stackoverflow.com/questions/24112771/cloudkit-for-sending-push-notifications-through-cron-jobs