2

My question is similar to this: How to detect if iCloud account on a device changed?

Apple docs says:

[[NSNotificationCenter defaultCenter]
    addObserver: self
       selector: @selector (iCloudAccountAvailabilityChanged:)
           name: NSUbiquityIdentityDidChangeNotification
         object: nil];

But I need a little bit more information about implementing correctly the 'iCloudAccountAvailabilityChanged:' method, because mine is never called, instead crashes my app.

Any answers would be greatly appreciated!

EDIT: I have in my didFinishLaunchingWithOptions:

self.currentiCloudToken= [NSFileManager defaultManager].ubiquityIdentityToken;

if(self.currentiCloudToken)
    {
        NSData *newTokenData=[NSKeyedArchiver archivedDataWithRootObject: self.currentiCloudToken];
        [[NSUserDefaults standardUserDefaults] setObject: newTokenData forKey: @"com.apple.MyWishList.UbiquityIdentityToken"];
        NSLog(@"You're logged in to iCloud! (from currentiCloudToken)");
        [[CKContainer defaultContainer]fetchUserRecordIDWithCompletionHandler:^(CKRecordID *recordID, NSError *error) {
            if(!error){
                NSLog(@"eltaroltam a usert: %@", recordID.recordName);
               [[NSUserDefaults standardUserDefaults]setValue:recordID.recordName forKey:@"userRecordID"];
                [self firstLaunch];
            }
            else
                NSLog(@"Probably not connected to internet:%@", [error localizedDescription]);
        }];
    }

    else
    {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey: @"com.apple.MyWishList.UbiquityIdentityToken"];
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Info" message:@"In order to share your wishes, you need to sign in to iCloud" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
}
Community
  • 1
  • 1
Zsolt
  • 49
  • 8
  • 1
    How have you implemented the iCloudAccountAvailabilityChanged: method, and a backtrace from the crash log would be useful. – Rob Glassey Nov 04 '14 at 18:07
  • no reports, simply just point to 'main' https://www.dropbox.com/sh/lklctrjmr653eur/AAAzVuSSwkmoneFC9HCgYJPza?dl=0 I've tried to implement several ways, no succeed, so its empty. Always the same result. No breakpoints set. – Zsolt Nov 04 '14 at 18:24
  • So my biggest problem is, when someone decide to log out from iCloud, and when it happens, that crashes the app. Same for signing in, not matter it is in the foreground or in the background. When someone has a signed in account, it works just fine, anytime. – Zsolt Nov 04 '14 at 18:37
  • I think it was discussed already in some other thread - when you change global settings for iCloud, iOS automatically stops all active apps. Now my own assumption: this notification is rather for switching flight mode or something like that. – Nick Entin Feb 11 '15 at 08:19
  • I get `SIGKILL` when iCloud is turned off, but sometimes the app will not be killed when you turn it on, then I receive this notification. – yano Jun 15 '17 at 17:29
  • I am having this same issue. For some reason Apple Docs and other research does not show an elegant way of handling this. – Jav Solo Oct 05 '21 at 20:25

0 Answers0