2020-03-28 17:51:14 -05:00
//
// CloudKitAccountViewController.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 3/28/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import UIKit
2024-12-04 17:36:08 -08:00
import SafariServices
2025-11-19 19:04:35 -08:00
import RSCore
2020-03-28 17:51:14 -05:00
import Account
2025-09-16 10:21:29 -07:00
final class CloudKitAccountViewController : UITableViewController {
2020-03-28 17:51:14 -05:00
weak var delegate : AddAccountDismissDelegate ?
2025-11-19 19:43:09 -08:00
@IBOutlet var footerLabel : UILabel !
2025-09-22 20:43:32 -07:00
2020-03-28 17:51:14 -05:00
override func viewDidLoad () {
super . viewDidLoad ()
2020-11-09 21:41:05 +08:00
setupFooter ()
2025-11-05 11:22:10 -08:00
2020-03-28 17:51:14 -05:00
tableView . register ( ImageHeaderView . self , forHeaderFooterViewReuseIdentifier : "SectionHeader" )
}
2025-11-05 11:22:10 -08:00
2020-11-09 21:41:05 +08:00
private func setupFooter () {
2024-12-04 17:36:08 -08: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 21:41:05 +08:00
}
2020-03-28 17:51:14 -05:00
@IBAction func cancel ( _ sender : Any ) {
dismiss ( animated : true , completion : nil )
delegate ?. dismiss ()
}
2025-11-05 11:22:10 -08:00
2020-03-28 17:51:14 -05:00
@IBAction func add ( _ sender : Any ) {
2025-09-22 20:43:32 -07:00
guard AddCloudKitAccountUtilities . isiCloudDriveEnabled else {
presentError ( AddCloudKitAccountError . iCloudDriveMissing )
2021-06-17 19:05:39 -05:00
return
}
2025-11-05 11:22:10 -08:00
2026-01-02 10:45:46 -08:00
_ = AccountManager . shared . createAccount ( type : . cloudKit )
2020-03-28 17:51:14 -05:00
dismiss ( animated : true , completion : nil )
delegate ?. dismiss ()
}
2025-11-05 11:22:10 -08:00
2020-03-28 17:51:14 -05:00
override func tableView ( _ tableView : UITableView , heightForHeaderInSection section : Int ) -> CGFloat {
return section == 0 ? ImageHeaderView . rowHeight : super . tableView ( tableView , heightForHeaderInSection : section )
}
2025-11-05 11:22:10 -08:00
2020-03-28 17:51:14 -05:00
override func tableView ( _ tableView : UITableView , viewForHeaderInSection section : Int ) -> UIView ? {
if section == 0 {
let headerView = tableView . dequeueReusableHeaderFooterView ( withIdentifier : "SectionHeader" ) as ! ImageHeaderView
2025-11-18 22:08:33 -08:00
headerView . imageView . image = Assets . accountImage (. cloudKit )
2020-03-28 17:51:14 -05:00
return headerView
} else {
return super . tableView ( tableView , viewForHeaderInSection : section )
}
}
2024-12-04 17:36:08 -08:00
@IBAction func openLimitationsAndSolutions ( _ sender : Any ) {
let vc = SFSafariViewController ( url : CloudKitWebDocumentation . limitationsAndSolutionsURL )
vc . modalPresentationStyle = . pageSheet
present ( vc , animated : true )
}
2020-03-28 17:51:14 -05:00
}