SkygearIO / skygear-SDK-iOS

Skygear SDK for iOS
https://skygear.io
Other
10 stars 28 forks source link

SKYDatabase saveSubscription failed #26

Closed a821246710 closed 8 years ago

a821246710 commented 8 years ago

error message : Failed to subscribe for my todo: Error Domain=SKYOperationErrorDomain Code=108 "The server is unable to process the data." UserInfo={arguments=<CFArray 0x125dae0f0 [0x19fcfa150]>{type = immutable, count = 1, values = (    0 : device_id )}, NSErrorFailingURLKey=https://todolist.skygeario.com/subscription/save, SKYErrorMessage=empty device_id, SKYErrorName=InvalidArgument, SKYOperationErrorHTTPStatusCodeKey=400, NSLocalizedDescription=The server is unable to process the data.}

 func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
        print("Registered for Push notifications with token: \(deviceToken)");
        SKYContainer.defaultContainer().registerRemoteNotificationDeviceToken(deviceToken) { (deviceID, error) in
            if error != nil {
                print("Failed to register device token: \(error)")
                return
            }

            print("deviceID : \(deviceID)")  // has deviceID
            let query = SKYQuery(recordType: "todo", predicate: nil)
            let sortDescriptor = NSSortDescriptor(key: "order", ascending: false)
            query.sortDescriptors = [sortDescriptor]
            let subscription = SKYSubscription(query: query, subscriptionID: "my todos")
            SKYContainer.defaultContainer().privateCloudDatabase.saveSubscription(subscription,completionHandler: { (subscription, error) in
                if error != nil {
                    print("Failed to subscribe for my todo: \(error)")  // error occur
                    return
                }

                print("Subscription successful.")
            })
        }
    }
cheungpat commented 8 years ago

It appears that SKYDatabase does not set the registered Device ID to subscription operations, therefore -[SKYDatabase saveSubscription:] does not work because there is no Device ID in the operation object.

There seems to be no test case for that -saveSubscription:.

Please use SKYModifySubscriptionOperation for the time being. We will fix this later.

a821246710 commented 8 years ago

and when I use SKYQuery to build SKYRecordStorage, I also got no Device ID subscribe query error

cheungpat commented 8 years ago

@limouren