Try to store Object in iCloud but don't see any action iOS -
i use this tutorials store object icloud (key-value storage).
my gui had 1 button triggers: pressbutton
method
here relevant code:
nsstring *const keystoragestr = @"keyforstore"; /* ... */ - (ibaction)pressbutton:(uibutton *)sender { score++; [demoicloudviewcontroller setscore: score]; scorecountlabel.text = [nsstring stringwithformat:@"%d", score]; // store preferences nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; [defaults setinteger:score forkey:keystoragestr]; // store icloud [self setinteger:score forkey:keystoragestr]; } - (void)setinteger:(int)value forkey:(nsstring*)key { [self setobject:[nsnumber numberwithint:value] forkey:key]; } - (void)setobject:(id)value forkey:(nsstring *)key { nsubiquitouskeyvaluestore *store = [nsubiquitouskeyvaluestore defaultstore]; if (store) { [store setobject:value forkey:key]; //[store synchronize]; } }
and handler:
nsubiquitouskeyvaluestore* store = [nsubiquitouskeyvaluestore defaultstore]; if (store) { [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(storechanged:) name:nsubiquitouskeyvaluestoredidchangeexternallynotification object:store]; [store synchronize]; } - (void)storechanged:(nsnotification*)notification {/* .. never called .. */}
here proper value: file://localhost/private/var/mobile/library/mobile%20documents/76z3cr95hf~com~wifi~icloud~wifi-icloud-demo/
- (void)viewdidload { [super viewdidload]; ubiq = [[nsfilemanager defaultmanager] urlforubiquitycontaineridentifier:nil]; if (ubiq) { nslog(@"icloud access @ %@", ubiq); isicloudactive = true; } else { nslog(@"no icloud access"); }
when added handler listen on everything:
nsnotificationcenter *notifycenter = [nsnotificationcenter defaultcenter]; [notifycenter addobserverforname:nil object:nil queue:nil usingblock:^(nsnotification* notification){ // explore notification nslog(@"notification found with:" "\r\n name: %@" "\r\n object: %@" "\r\n userinfo: %@", [notification name], [notification object], [notification userinfo]); }];
i get:
name: _uiapplicationsystemgesturestatechangednotification object: (null) userinfo: (null)
from xcode icloud stats:
please help,
thanks,
what happens if delete app , re-run it? can retrieve value icloud? unless there's other configuration problem you've not mentioned, guess can.
the reason: notification you're expecting see happens when change comes icloud (i.e., originating device). notification will not triggered when save value -- why be? know value has been written!
Comments
Post a Comment