ios - iCloud connects on simulator but not on device -



i'm new in programming ios , have got problem couldn't icloud connection if run app on real device.
app runs perfect on simulator , if disconnect device mac.
have idea how can fix it?
code have written connect icloud

    self.filemanager = [nsfilemanager defaultmanager];      dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{         self.ubiquityidentifier = [self.filemanager urlforubiquitycontaineridentifier:nil];     });      dispatch_async(dispatch_get_main_queue(), ^{         if(self.ubiquityidentifier)         {             [[nsnotificationcenter defaultcenter] postnotificationname:kicloudavailablenotification object:self.ubiquityidentifier];             [self startmediaquery];         }         else         {             [[nsnotificationcenter defaultcenter] postnotificationname:kicloudnotavailablenotification object:self.ubiquityidentifier];             nslog(@"icloud not available");         }     }); 

if device connected go in else block , if test in simulator or on not connected device works fine.
lot.
weissja19

assuming you're detecting failure because nslog prints "icloud not available" message, you're setting classic race condition here:

  1. you set value of self.ubiquityidentifier on global (non-main) queue.
  2. you test value self.ubiquityidentifier on main queue.

the 2 dispatch_async calls run on different queues. result, there's no guarantee you're setting value of self.ubiquityidentifier before test it. work sometimes, , fail @ others, , not obvious reason. when "icloud not available" message, it's because second queue checked value before assigned value.

the fix change dispatch calls can guarantee order of execution. 2 possibilities are:

  1. combine these 2 dispatch_async calls of code happens on same queue, or
  2. move second dispatch_async inside first, don't dispatch main queue until you've set value self.ubiquityidentifier.

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -