ios - How can each iCloud user save a user specific subscription in CloudKit? -


i’m having issue creating subscriptions in public cloudkit database. code works fine when saving subscription first icloud user fails trying save different subscription against same record type second icloud user.

here code saves subscription (answers in swift fine too):

cknotificationinfo *info = [[cknotificationinfo alloc] init]; info.shouldsendcontentavailable = yes;  ckreference *ref = [[ckreference alloc] initwithrecordid:_ckuserid action:ckreferenceactionnone]; nspredicate *pred = [nspredicate predicatewithformat:@"user == %@", ref]; nsstring *subid = [nsstring stringwithformat:@"access-%@", _ckuserid.recordname];  cksubscription *sub = [[cksubscription alloc] initwithrecordtype:@"access" predicate:pred subscriptionid:subid options:cksubscriptionoptionsfiresonrecordcreation | cksubscriptionoptionsfiresonrecordupdate | cksubscriptionoptionsfiresonrecorddeletion]; sub.zoneid = [ckrecordzone defaultrecordzone].zoneid; sub.notificationinfo = info;  ckmodifysubscriptionsoperation *op = [[ckmodifysubscriptionsoperation alloc] initwithsubscriptionstosave:@[ sub ] subscriptionidstodelete:nil]; op.modifysubscriptionscompletionblock = ^(nsarray<cksubscription *> *savedsubscriptions, nsarray<nsstring *> *deletedsubscriptionids, nserror *operationerror) {     if (operationerror) {         rmlogerror(@"error trying update user's access subscription: %@", operationerror);     } else {         rmloginfo(@"user access subscription added");     } }; [_ckdatabase addoperation:op]; 

_ckuserid ckrecordid representing current icloud user.
_ckdatbase ckdatabase reference public database of current cloudkit container.

when code run on device user a, subscription saved fine.

when code run on device b user b, subscription fails following message in log:

2016-04-19 11:38:42:504 myapp[560:f03] error trying update user's access subscription: <ckerror 0x147830530: "partial failure" (2/1011); "failed modify subscriptions"; uuid = 98e9f99a-c4f6-4488-8087-45285a7c1db1; container id = "icloud.com.blah.myapp"; partial errors: { access-_df09e8908eeb9b9f12ebbe935e389d51 = <ckerror 0x14664b4e0: "unknown item" (11/2003); server message = "did not find required record type: _sub_trigger_sub_08b399dc1448e58993a967b704a07ee0"> }>

the access record type has user field reference ckrecordid representing icloud user id.

my goal here have subscription each user allows app know whenever record specific current user added, updated, or deleted table.

why can’t save 2nd subscription, 2nd user, record type? i’m giving each subscription own unique id based on user id.

i created simple test app replicate problem , of course worked fine in test app.

i went real app , after digging got issue resolved. did 2 things:

  1. in cloudkit dashboard deleted existing subscription types.
  2. i fixed bug in code mistakenly setting subscription's zoneid defaultrecordzone. though not related posted problem, bug preventing notifications reaching devices unless device logged same icloud account used add/update/delete record.

basically strange error fixed resetting things in dashboard , restarting app.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -