ios - CKSubscription not working -


i creating 2 cksubscriptions in app delegate's didfinishlaunchingwithoptions method such.

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     // override point customization after application launch.      uiusernotificationsettings *notificationsettings = [uiusernotificationsettings settingsfortypes:uiusernotificationtypealert categories:nil];     [[uiapplication sharedapplication] registerusernotificationsettings:notificationsettings];     [[uiapplication sharedapplication] registerforremotenotifications];      _mycontainer = [ckcontainer containerwithidentifier:@"icloud.com.isaranjha.copyfeed"];     _privatedatabase = [_mycontainer privateclouddatabase];      [_privatedatabase fetchsubscriptionwithid:@"subscription" completionhandler:^(cksubscription *subscription, nserror *error){          if (subscription) {          } else {              nspredicate *predicate = [nspredicate predicatewithvalue:yes];             cksubscription *subscription = [[cksubscription alloc] initwithrecordtype:@"strings" predicate:predicate subscriptionid:@"subscription" options:cksubscriptionoptionsfiresonrecordcreation | cksubscriptionoptionsfiresonrecorddeletion | cksubscriptionoptionsfiresonrecordupdate];             cknotificationinfo *notificationinfo = [cknotificationinfo new];             notificationinfo.alertbody = @"";             notificationinfo.shouldsendcontentavailable = yes;             subscription.notificationinfo = notificationinfo;              [_privatedatabase savesubscription:subscription completionhandler:^(cksubscription *subscription, nserror *error) {              }];          }      }];       [_privatedatabase fetchsubscriptionwithid:@"subscription1" completionhandler:^(cksubscription *subscription, nserror *error){          if (subscription) {          } else {              nspredicate *predicate1 = [nspredicate predicatewithvalue:yes];             cksubscription *subscription1 = [[cksubscription alloc] initwithrecordtype:@"images" predicate:predicate1 subscriptionid:@"subscription1" options:cksubscriptionoptionsfiresonrecordcreation | cksubscriptionoptionsfiresonrecorddeletion | cksubscriptionoptionsfiresonrecordupdate];             cknotificationinfo *notificationinfo1 = [cknotificationinfo new];             notificationinfo1.shouldsendcontentavailable = yes;             notificationinfo1.alertbody = @"";             subscription1.notificationinfo = notificationinfo1;             [_privatedatabase savesubscription:subscription1 completionhandler:^(cksubscription *subscription, nserror *error) {              }];          }      }];      viewcontroller *view = [[viewcontroller alloc] init];      uinavigationcontroller *navcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:view];     self.window.rootviewcontroller = navcontroller;      return yes; } 

those created successfully, when log out nserror, returns null , every time open app after that, able fetch them correctly. however, when record created or deleted, on 1 device, iphone, notification doesn't fire (or not being received) on other device, mac. here how listening notifications on mac.

- (void)application:(nsapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo {      nslog(@"cksubscription received.");      ckquerynotification *cloudkitnotification = [ckquerynotification notificationfromremotenotificationdictionary:userinfo];      [[nsnotificationcenter defaultcenter] postnotificationname:@"cloudkitupdated" object:nil userinfo:@{@"cknotification" : cloudkitnotification}]; } 

that nslog unfortunately never fires.

you have empty alertbody

notificationinfo1.alertbody = @"";

with won't receive push notifications when app not active. when manually activate app able query notifications using ckfetchnotificationchangesoperation. here snippet of how use in evcloudkitdao:

public func fetchchangenotifications(skiprecordid: ckrecordid?, inserted:(recordid:string, item: evcloudkitdataobject) -> void, updated:(recordid: string, item: evcloudkitdataobject) -> void, deleted:(recordid: string) -> void, completed:()-> void) {     var defaults = nsuserdefaults.standarduserdefaults()     var array: [nsobject] = [nsobject]()     var operation = ckfetchnotificationchangesoperation(previousserverchangetoken: self.previouschangetoken)     operation.notificationchangedblock = { notification in         if notification.notificationtype == .query  {             if var querynotification = notification as? ckquerynotification {                 array.append(notification.notificationid)                 if skiprecordid != nil && skiprecordid?.recordname != querynotification.recordid.recordname {                     if querynotification.querynotificationreason == .recorddeleted {                         deleted(recordid: querynotification.recordid.recordname)                     } else {                         evcloudkitdao.publicdb.getitem(querynotification.recordid.recordname, completionhandler: { item in                             evlog("getitem: recordtype = \(evreflection.swiftstringfromclass(item)), keys , values:")                             evreflection.logobject(item)                             if querynotification.querynotificationreason == .recordcreated {                                 inserted(recordid: querynotification.recordid.recordname, item: item)                             } else if querynotification.querynotificationreason == .recordupdated {                                 updated(recordid: querynotification.recordid.recordname, item: item)                             }                         }, errorhandler: { error in                             evlog("error: getitem change notification.\n\(error.description)")                         })                     }                 }             }         }     }     operation.fetchnotificationchangescompletionblock = { changetoken, error in         var op = ckmarknotificationsreadoperation(notificationidstomarkread: array)         op.start()         evlog("changetoken = \(changetoken)")         self.previouschangetoken = changetoken          if operation.morecoming  {             self.fetchchangenotifications(skiprecordid, inserted: inserted, updated: updated, deleted: deleted, completed:completed)         } else {             completed()         }     }     operation.start() } 

when app active, should receive notifications in application didreceiveremotenotification.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -