使用CloudKit CKQuery,您可以过滤距离(参见示例).但你怎么能对距离进行排序呢?喜欢位置ASC.位置上的排序描述符返回错误query.sortDescriptors = [NSSortDescriptor(key: "distanceToLocation", ascending: true)]:
static func getNearbySpots(location : CLLocation, completionHandler: (spots : CKRecord[]) -> Void) {
let predicate = NSPredicate(format: "distanceToLocation:fromLocation:(location, %@) < 10000", location)
let queryOperation = CKQueryOperation(query: query)
var results : CKRecord[] = []
queryOperation.recordFetchedBlock = {
results += $0
}
queryOperation.queryCompletionBlock = {
if $1 {
NSLog($1.description,[])
abort()
} else {
completionHandler(spots: results)
}
}
self.publicDB().addOperation(queryOperation)
}
Run Code Online (Sandbox Code Playgroud) 我正在使用具有"跟随"引用列表属性的用户记录类型的CloudKit支持的应用程序.我正在尝试构建一个查询以获取跟随指定用户的每个用户(即指定用户在以下引用列表中显示为条目的那些用户).
我正在尝试构建我NSPredicate的CKQuery原样:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@ IN following", [[CKReference alloc] initWithRecordID:currentUserID action:CKReferenceActionNone]];
CKQuery *query = [[CKQuery alloc] initWithRecordType:UserRecordType predicate:predicate];
Run Code Online (Sandbox Code Playgroud)
并且CloudKit返回以下错误消息:
"Unknown Item" (11/2003); server message = "did not find required record type";
Run Code Online (Sandbox Code Playgroud)
我觉得我的谓词中可能会遗漏一些相当直接的东西.任何帮助将不胜感激!
我为cloudkit设置了订阅通知.这是我的代码:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"];
CKSubscription *subscription = [[CKSubscription alloc]
initWithRecordType:recordType
predicate:predicate
options:CKSubscriptionOptionsFiresOnRecordCreation];
CKNotificationInfo *notificationInfo = [CKNotificationInfo new];
notificationInfo.alertLocalizationKey =@"New record in cloudKit";
notificationInfo.shouldBadge = YES;
notificationInfo.soundName = UILocalNotificationDefaultSoundName;
notificationInfo.shouldSendContentAvailable = YES;
subscription.notificationInfo = notificationInfo;
CKContainer *container = [CKContainer defaultContainer];
CKDatabase *publicDatabase = [container publicCloudDatabase];
[publicDatabase saveSubscription:subscription
completionHandler:^(CKSubscription *subscription, NSError *error) {
if (!error)
{
NSLog(@"no error");
}
else
{
NSLog(@"error%@", error);
}
}];
Run Code Online (Sandbox Code Playgroud)
工作得很好.问题是徽章,他们看起来像cloudKit没有重置徽章号码,并且即使我将徽章计数设置为零,也会不断增加.
- (void)applicationDidBecomeActive:(UIApplication *)application
{
application.applicationIconBadgeNumber = 0;
}
Run Code Online (Sandbox Code Playgroud)
当应用程序收到新通知时,从0到5(每个新通知增加1,下一次将是6)
你们中的任何人都知道如何从cloudkit中跟踪正确的徽章数量(在Objective-C中)
我有足够的记录手动预装到CloudKit但在开发环境中.
当我部署开发环境时,记录没有移动到生产环境中.这真的很烦人.移动记录的任何简单方法?
CloudKit具有一些非常严格的数据限制,限制为50MB的数据库存储加上每个用户1MB,数据库带宽为250KB /天,每个用户为5KB.
要了解CloudKit如何将数据库结构和协议开销合并到这些数字中,是否有一个仪表板,我能够查看记录或表的大小,或消耗的带宽量?
我注意到很多人使用Obj-C创建iCloud应用程序并导入.h等.对于像我这样的菜鸟看起来非常复杂,因为我从一开始就使用Swift.人们说只能使用Swift和CloudKit创建iCloud应用程序.可能吗?谢谢
我正在使用Apple的新CloudKit JS参考和示例代码来构建一个简单的CRUD应用程序.在我甚至可以进入CRUD之前,我被Apple身份验证停止了.
index.html
<html>
<body>
<div id="apple-sign-in-button">Sign in
<span id="username"></span>
</div>
<script>
/*
* Initialize the global objects we will need.
*/
if(typeof CKCatalog === 'undefined') {
CKCatalog = {};
}
if(typeof CKCatalog.tabs === 'undefined') {
CKCatalog.tabs = {
'readme': [{}],
'not-found': [{}]
};
}
</script>
<script src="js/init.js"></script>
<script src="js/cloudkit-code-samples/authentication.js"></script>
<script>
window.addEventListener('cloudkitloaded',CKCatalog.init);
</script>
<script async src="https://cdn.apple-cloudkit.com/ck/1/cloudkit.js"> </script>
</body>
Run Code Online (Sandbox Code Playgroud)
包括div id ="apple-sign-in-button"和span id ="username"除去了所有错误,除了:
无法加载资源:服务器响应状态为421(错误请求).
在任何其他地方提及此错误通常都与SMTP或FTP绑定.知道发生了什么事吗?
我正在尝试更新CloudKit中的现有记录,但我正在创建一个新记录,而不是更改值!这是代码:
func pairing(phone: String, ctid: String) {
ctUsers = [CKRecord]()
print("THE PHONE IS: \(phone)\n")
let publicData = CKContainer.default().publicCloudDatabase
let predicate = Predicate(format: "phone == %@", phone)
let query = CKQuery(recordType: "Elder", predicate: predicate)
publicData.perform(query, inZoneWith: nil) { (results: [CKRecord]?, error: NSError?) -> Void in
if error != nil {
print(error?.localizedDescription)
}
if let users = results {
self.ctUsers = users
print("\nHow many users in cloud: \(self.ctUsers.count)\n")
if self.ctUsers.count != 0 {
let user = CKRecord(recordType: "Elder")
user["careTakerId"] = ctid
let …Run Code Online (Sandbox Code Playgroud) 我使用CloudKit和Core Data与Swift来同步我的数据.因此,我创建了订阅,在收到通知后,我从云端获取新数据以更新我的核心数据.这是处理此更新的推荐方法.为了获取数据更改,我可以插入一个CKServerChangeToken来获取新的东西.我的问题是如何将令牌保存到Core Data以便以后获取请求?对于CKRecords,有一种方法只保存元数据,但CKServerChangeToken没有这样的东西.有没有人有想法?
最好的问候,Jannik
更新,2016年6月:截至NSPersistentStoreCoordinator的最新文档,与iCloud的Core Data相关的所有内容都标记为已弃用.因此,应该避免新的开发.
使用Core Data,iCloud和CloudKit进行同步和备份以及它如何协同工作
重要信息iCloud与Core Data的使用已被弃用,不再受支持.
我一直在阅读有关将iCloud与Core Data集成的内容.上面提到的Stack Overflow回答提到了将核心数据库同步到iCloud的可能性,但也说它已被弃用了. 什么技术应该取代它.是CloudKit吗?有人可以指出有关如何将Core Data与云同步集成的文档(无论哪种API /技术应该替换它)
cloudkit ×10
ios ×7
icloud ×4
swift ×3
core-data ×2
ckquery ×1
html ×1
ipad ×1
iphone ×1
javascript ×1
nspredicate ×1
web-services ×1