Detect iCloud sync errors due to not being signed in or not having iCloud Drive enabled and inform the user giving option to open Settings. If the user declines to open Settings do not ask again this until app is closed and opens again.

This commit is contained in:
Mark Jerde 2018-02-15 14:10:14 -06:00
parent 8f634d41a9
commit 82350d9fda

View file

@ -8,7 +8,7 @@
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, FlycutStoreDelegate, FlycutOperatorDelegate {
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, FlycutStoreDelegate, FlycutOperatorDelegate, MJCloudKitUserDefaultsSyncDelegate {
let flycut:FlycutOperator = FlycutOperator()
var activeUpdates:Int = 0
@ -17,6 +17,7 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
var pbCount:Int = -1
var rememberedSyncSettings:Bool = false
var rememberedSyncClippings:Bool = false
var ignoreCKAccountStatusNoAccount = false
let pasteboardInteractionQueue = DispatchQueue(label: "com.Flycut.pasteboardInteractionQueue")
let alertHandlingSemaphore = DispatchSemaphore(value: 0)
@ -37,6 +38,8 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
// Use this command to get screenshots:
// while true; do xcrun simctl io booted screenshot;sleep 1;done
MJCloudKitUserDefaultsSync.setDelegate(self)
if ( UserDefaults.standard.bool(forKey: "demoForAppStoreScreenshots") )
{
// Ensure we will not load or save clippings in demo mode.
@ -440,5 +443,27 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
}
}
}
func notifyCKAccountStatusNoAccount() {
if ( !ignoreCKAccountStatusNoAccount )
{
let alert = UIAlertController(title: "No iCloud Account", message: "An iCloud account with iCloud Drive enabled is required for iCloud sync.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Preferences", style: .default, handler: { (_) in
if #available(iOS 10.0, *)
{
// Opens iCloud Prefs < iOS 11.0, main Prefs >= iOS 11.0
UIApplication.shared.openURL(URL(string: "App-Prefs:root=CASTLE")!)
}
else
{
UIApplication.shared.openURL(URL(string: "prefs:root=CASTLE")!)
}
}))
alert.addAction(UIAlertAction(title: "Ignore", style: .cancel, handler: { (_) in
self.ignoreCKAccountStatusNoAccount = true
}))
self.present(alert, animated: true, completion: nil)
}
}
}