Is it possible to intercept iCloud switching on/off in Settings -> iCloud -> Document & Data?

后端 未结 3 396
抹茶落季
抹茶落季 2020-12-19 18:06

Is it possible to intercept if the user switches from on to off the iCloud support under Settings -> iCloud -> Document & Data<

3条回答
  •  难免孤独
    2020-12-19 18:54

    It's not possible to intercept the changes, but you can programmatically check to see if they have iCloud enabled:

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

    When your app enters the background, you could periodically poll this and have your app respond to any change in state.

    EDIT: If your app is running and the user changes enables or disable Document & Data iCloud syncing via the settings app, your app will receive the SIGKILL signal. However, the OS can terminate your app for a number of reasons so trapping SIGKILL is not a reliable method of intercepting iCloud sync setting changes. You are still better off periodically polling.

提交回复
热议问题