Is it possible to intercept on / off iCloud in the settings & # 8594; iCloud & # 8594; Document and data?

Is it possible to intercept if a user switches from turned on to iCloud under SettingsiCloudDocument and Data

Obviously, when he does this, the application has already resigned and launched the background. I focus on iOS7, and I would like to synchronize with UIManagedDocument, otherwise it would be like having two different UIDocuments: one with iCloud support and all the data created before switching from on to off and new without any data in it. If I create data when iCloud support is disabled and then turn on again, I get the same DB that I had when support was disabled.

Note . I believe nelico's answer is right. He wrote: "If your application is running and the user changes, enables or disables the synchronization of documents and iCloud data through the settings application, your application will receive a SIGKILL signal."

When the user changes the settings, the application is ALREADY in the background and receives a SIGKILL signal. This is what I do not understand, and I do not want. Registering for NSUbiquityIdentityDidChangeNotificationdoes not solve this problem .

+2
source share
3 answers

, NSUbiquityIdentityDidChangeNotification, , URLForUbiquityContainerIdentifier, , , " ". , , , iCloud. , , Apple Geniuses iCloud, - .

:

id <NSObject,NSCopying,NSCoding> _currentUbiquityIdentityToken;

...

_currentUbiquityIdentityToken = [[NSFileManager defaultManager] ubiquityIdentityToken];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (_iCloudAccountAvailabilityChanged:) name: NSUbiquityIdentityDidChangeNotification object: nil];

...

- (void)_iCloudAccountAvailabilityChanged:(NSNotification*)notif {
    if (![_currentUbiquityIdentityToken isEqual:[[NSFileManager defaultManager] ubiquityIdentityToken]]) {
        // Update the current token and rescan for documents.
        _currentUbiquityIdentityToken = [[NSFileManager defaultManager] ubiquityIdentityToken];
        // Do something about the change here...
    }
}
+2

. , ( ), , . UIManagedDocument iCloud , .

, , , iCloud. , , .

/*! The app is about to enter foreground so use this opportunity to check if the user has changed any
    settings.  They may have changed the iCloud account, logged into or out of iCloud, set Documents & Data to off (same effect as
    if they logged out of iCloud) or they may have changed the app specific settings.
    If the settings have been changed then check if iCloud is being turned off and ask the user if they want to save the files locally.
    Otherwise just copy the files to iCloud (don't ask the user again, they've just turned iCloud on, so they obviously mean it!)

 @param application The application
 */
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    //LOG(@"applicationWillEnterForeground called");

    // Check if the settings have changed
    [[NSUserDefaults standardUserDefaults] synchronize];
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
    bool userICloudChoice = [userDefaults boolForKey:_cloudPreferenceKey];

    // Check against the current in memory setting
    if (userICloudChoice  == useICloudStorage) {

        // The setting has not been changed so just ignore
        //LOG(@" iCloud choice has not changed");


    } else {

        // The setting has changed so do something
        //LOG(@" iCloud choice has been changed!!");

        // iCloud has been turned off so ask the user if they want to keep files locally
        if (!userICloudChoice) {
            //LOG(@" Ask user if  they want to keep iCloud files ?");

            if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
                _cloudChangedAlert = [[UIAlertView alloc] initWithTitle:@"You're not using iCloud" message:@"What would you like to do with documents currently on this phone?" delegate:self cancelButtonTitle:@"Keep using iCloud" otherButtonTitles:@"Keep on My iPhone", @"Delete from My iPhone", nil];
            } else {
                _cloudChangedAlert = [[UIAlertView alloc] initWithTitle:@"You're not using iCloud" message:@"What would you like to do with documents currently on this phone?" delegate:self cancelButtonTitle:@"Keep using iCloud" otherButtonTitles:@"Keep on My iPad", @"Delete from My iPad", nil];

            }

            [_cloudChangedAlert show];

        } else {

            // iCloud has been turned on so just copy the files across, don't ask the user again...

            //LOG(@" iCloud turned on so copy any created files across");
            [[CloudManager sharedManager] setIsCloudEnabled:YES];  // This does all the work based on the settings passed to it
            useICloudStorage = YES;

        }
    }

}

Oh, , iCloud.

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

, , iCloud:

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *ubiquityContainerURL = [fileManager URLForUbiquityContainerIdentifier:nil];
if (!ubiquityContainerURL) {
    // iCloud is not enabled
}

, , .

:. , SIGKILL. , SIGKILL iCloud. .

0
source

All Articles