CloudKit - 无法从iCloud检索数据

时间:2016-08-12 11:08:14

标签: ios swift cloudkit

当应用程序(iOS9)通过Xcode运行或从App Store下载时,通过CloudKit从iCloud发送和接收数据有什么不同吗?

我的问题是:从Xcode启动的应用程序成功接收并显示数据,App Store中发布的相同应用程序无法显示数据...

可能是什么错误?

谢谢。

func getRecordsFromCloud() {
        // Fetch data using Convenience API
        let cloudContainer = CKContainer.defaultContainer()
        let publicDatabase = cloudContainer.publicCloudDatabase
        let predicate = NSPredicate(value: true)
        let query = CKQuery(recordType: "Pivo", predicate: predicate)
        query.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]

        // Create the query operation with the query
        let queryOperation = CKQueryOperation(query: query)
        queryOperation.desiredKeys = ["name", "type", "location"]
        queryOperation.queuePriority = .VeryHigh
        queryOperation.resultsLimit = 50
        queryOperation.recordFetchedBlock = { (record:CKRecord!) -> Void in
            if let restaurantRecord = record {
                self.restaurants.append(restaurantRecord)
            }
        }

        queryOperation.queryCompletionBlock = { (cursor:CKQueryCursor?, error:NSError?) -> Void in
            if (error != nil) {
                print("Failed to get data from iCloud - \(error!.localizedDescription)")
                return
            }

            print("Successfully retrieve the data from iCloud")
            self.refreshControl?.endRefreshing()
            NSOperationQueue.mainQueue().addOperationWithBlock() {
                self.spinner.stopAnimating()
                self.tableView.reloadData()
            }

        }

        // Execute the query
        publicDatabase.addOperation(queryOperation)
    }

1 个答案:

答案 0 :(得分:0)

您需要使用CloudKit仪表板将开发环境迁移到生产环境