Game Development Reference
In-Depth Information
1. In our app launch in the
applica-
tion:didFinishLauchingWithOptions
method, get
ubiquityIden-
tityToken
from
NSFileManager
.
NSFileManager* fileManager = [NSFileManager
defaultManager];
id currentiCloudToken =
fileManager.ubiquityIdentityToken;
2. Then archive the iCloud availability in the user defaults database by the
ubi-
quityIdentityToken
property fetched using
NSFileManager
.
if (currentiCloudToken)
{
NSData *newTokenData = [NSKeyedArchiver
archivedDataWithRootObject:currentiCloudToken];
[[NSUserDefaults
standardUserDefaults]setObject:newTokenData
forKey:@"com.mb.FlyingSpaceship.UbiquityIdentityToken"];
}
else
{
[[NSUserDefaults standardUserDefaults]
removeObjectForKey:
@"com.mb.FlyingSpaceship.UbiquityIdentityToken"];
}
3. Now the
currentiCloudToken
function saved is the unique token represent-
ing the currently active iCloud account. Using this we can compare to detect
whether the current account is different from the previous one.
4. When the user will enables airplane mode, iCloud will itself become inaccessible,
but the current iCloud account will remain signed in and
ubiquityIden-
tityToken
contains the token of the current iCloud account.
5. For the user who signs out of iCloud, the value of
ubiquityIdentityToken
sets to
nil
. So to receive notification, we should register as an observer of the
NSUbiquityIdentityDidChangeNotification
notification where the
token is received. This is a notification for iCloud availability change and we can
handle it accordingly in the notification selector
iCloudAccountAvailab-
ilityChanged
.