iOS 9 CloudKit: query does not return anything while connected to cellular network

南楼画角 提交于 2019-11-26 21:33:48

问题


I'm developing an app with xcode 7 beta 5. When i run my app on my iphone 6 and i try to connect it to CloudKit if my iphone works in wifi mode all it's ok, i display all my data; but if my iphone works in LTE mode i can't see any kind of data. Does anyone know how to do this?

    func getRecordsFromCloud() {  

    lavori = []  

    /  

    let _cloudContainer = CKContainer.defaultContainer()  
    let publicDatabase = CKContainer.defaultContainer().publicCloudDatabase  

    /  

    let predicate = NSPredicate(value: true)  
    let query = CKQuery(recordType: "Lavori", predicate: predicate)  

    /  

    let queryOperation = CKQueryOperation(query: query)  

    queryOperation.desiredKeys = ["image","name"]  
    queryOperation.queuePriority = .VeryHigh  
    queryOperation.resultsLimit = 50  

    queryOperation.recordFetchedBlock = { (record:CKRecord) -> Void in  

        let lavoriRecord = record  

        self.lavori.append(lavoriRecord)  



    }  

    queryOperation.queryCompletionBlock = { (cursor:CKQueryCursor?, error:NSError?) -> Void in  

        if (error != nil) {  

            print("Failed to get data from iCloud - \(error!.localizedDescription)")  

        }  
        else {  

            print("Successfully retrieve the data from iCloud")  

            dispatch_async(dispatch_get_main_queue(), {  
                self.tableView.reloadData()  

            })  

        }  

    }  

    /  

    publicDatabase.addOperation(queryOperation)  

}  

Thanks, Alessio


回答1:


Open the settings app, find your app, enable 'use mobile data'

Update: As discussed below Adding the following line of code solved the problem:

queryOperation.qualityOfService = .UserInteractive

The reason why this works must be a timing / load issue. My initial guess would be that this is caused by this line:

queryOperation.queuePriority = .VeryHigh

The documentations states for the .queuePriority this: You should use priority values only as needed to classify the relative priority of non-dependent operations.

The documentation states for the .qualityOfService this: The default value of this property is NSOperationQualityOfServiceBackground and you should leave that value in place whenever possible.

So please try removing both the .queuePriority and .qualityOfService and see if it's working.

Update 2: Apparently this is a CloudKit bug. More people have the same issue. Please report it at https://bugreport.apple.com



来源:https://stackoverflow.com/questions/32493698/ios-9-cloudkit-query-does-not-return-anything-while-connected-to-cellular-netwo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!