2020-03-28 23:51:14 +01:00
//
// C l o u d K i t A c c o u n t V i e w C o n t r o l l e r . s w i f t
// N e t N e w s W i r e - i O S
//
// C r e a t e d b y M a u r i c e P a r k e r o n 3 / 2 8 / 2 0 .
// C o p y r i g h t © 2 0 2 0 R a n c h e r o S o f t w a r e . A l l r i g h t s r e s e r v e d .
//
import UIKit
2022-09-23 03:25:03 +02:00
import SafariServices
2020-03-28 23:51:14 +01:00
import Account
2021-06-18 02:05:39 +02:00
enum CloudKitAccountViewControllerError : LocalizedError {
case iCloudDriveMissing
var errorDescription : String ? {
return NSLocalizedString ( " Unable to add iCloud Account. Please make sure you have iCloud and iCloud enabled in System Preferences. " , comment : " Unable to add iCloud Account. " )
}
}
2020-03-28 23:51:14 +01:00
class CloudKitAccountViewController : UITableViewController {
weak var delegate : AddAccountDismissDelegate ?
2020-11-09 14:41:05 +01:00
@IBOutlet weak var footerLabel : UILabel !
2020-03-28 23:51:14 +01:00
override func viewDidLoad ( ) {
super . viewDidLoad ( )
2020-11-09 14:41:05 +01:00
setupFooter ( )
2020-03-28 23:51:14 +01:00
tableView . register ( ImageHeaderView . self , forHeaderFooterViewReuseIdentifier : " SectionHeader " )
}
2020-11-09 14:41:05 +01:00
private func setupFooter ( ) {
2022-09-23 03:25:03 +02:00
footerLabel . text = NSLocalizedString ( " NetNewsWire will use your iCloud account to sync your subscriptions across your Mac and iOS devices. " , comment : " iCloud " )
2020-11-09 14:41:05 +01:00
}
2020-03-28 23:51:14 +01:00
@IBAction func cancel ( _ sender : Any ) {
dismiss ( animated : true , completion : nil )
delegate ? . dismiss ( )
}
@IBAction func add ( _ sender : Any ) {
2021-06-18 02:05:39 +02:00
guard FileManager . default . ubiquityIdentityToken != nil else {
presentError ( CloudKitAccountViewControllerError . iCloudDriveMissing )
return
}
2020-04-01 23:45:29 +02:00
let _ = AccountManager . shared . createAccount ( type : . cloudKit )
2020-03-28 23:51:14 +01:00
dismiss ( animated : true , completion : nil )
delegate ? . dismiss ( )
}
override func tableView ( _ tableView : UITableView , heightForHeaderInSection section : Int ) -> CGFloat {
return section = = 0 ? ImageHeaderView . rowHeight : super . tableView ( tableView , heightForHeaderInSection : section )
}
override func tableView ( _ tableView : UITableView , viewForHeaderInSection section : Int ) -> UIView ? {
if section = = 0 {
let headerView = tableView . dequeueReusableHeaderFooterView ( withIdentifier : " SectionHeader " ) as ! ImageHeaderView
headerView . imageView . image = AppAssets . image ( for : . cloudKit )
return headerView
} else {
return super . tableView ( tableView , viewForHeaderInSection : section )
}
}
2022-09-23 03:25:03 +02:00
@IBAction func openLimitationsAndSolutions ( _ sender : Any ) {
2022-09-24 12:28:01 +02:00
let vc = SFSafariViewController ( url : CloudKitWebDocumentation . limitationsAndSolutionsURL )
2022-09-23 03:25:03 +02:00
vc . modalPresentationStyle = . pageSheet
present ( vc , animated : true )
}
2020-03-28 23:51:14 +01:00
}