0
我正在使用CloudKit在應用程序中工作,並且正在創建訂閱CloudKit。這裏是我的代碼:CloudKit:查詢訂閱請求
CKSubscription *subscription = [[CKSubscription alloc]
initWithRecordType:recordType
predicate:predicate
options:CKSubscriptionOptionsFiresOnRecordCreation |
CKSubscriptionOptionsFiresOnRecordUpdate |
CKSubscriptionOptionsFiresOnRecordDeletion];
CKNotificationInfo *notificationInfo = [CKNotificationInfo new];
notificationInfo.shouldSendContentAvailable = YES;
subscription.notificationInfo = notificationInfo;
notificationInfo.shouldBadge = YES;
CKDatabase *publicDatabase = [container publicCloudDatabase];
[publicDatabase saveSubscription:subscription
completionHandler:^(CKSubscription *subscription, NSError *error) {
if (!error)
{
NSLog(@"subscription success!");
}
else
{
NSLog(@"subscription error%@", error.localizedDescription);
}
}];
我的問題給你們。我如何查詢或驗證用戶訂閱CloudKit?
喜@EdwinVermeer。我已經嘗試了您的想法,並且謂詞在tableview中正確工作,但與訂閱無關。我懷疑這是我的訂閱設置,因爲我可以得到一個真正的謂詞來工作。我的謂詞涉及CKReference到當前用戶,在那裏我想獲得其他用戶對當前用戶發表的評論的通知 - let predicate = NSPredicate(format:「user!=%@ AND userIDForPost =%@」,argumentArray :[userRef,userRef])'。 userRef是當前用戶的ID,「user」是對其他用戶的引用,userIDForPost是對當前用戶的引用。超級讚賞任何幫助。 –
我在答案中添加了一些信息。你有嗎?除此之外,你是否在設備上使用iCloud? –
是的,我在AppDelegate中有這些方法。並且該設備使用其他用戶的帳戶登錄到iCloud。然後我進入儀表板並創建新記錄以匹配我自己帳戶下的謂詞,我認爲蘋果公司建議這樣做。過去幾個月我嘗試了很多東西,我開始懷疑這是否是一個錯誤。非常感謝你的幫助! @EdwinVermeer。 –