Improves App ID counting + management

Fetches App ID count directly from Apple, and adds AppIDsViewController to view all App IDs for the logged-in account.
This commit is contained in:
Riley Testut
2020-02-10 17:30:11 -08:00
parent 390a770115
commit 5045c1057a
14 changed files with 951 additions and 102 deletions

View File

@@ -113,6 +113,8 @@ class MyAppsViewController: UICollectionViewController
super.viewWillAppear(animated)
self.updateDataSource()
self.fetchAppIDs()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
@@ -142,6 +144,10 @@ class MyAppsViewController: UICollectionViewController
let installedApp = self.dataSource.item(at: indexPath)
return !installedApp.isSideloaded
}
@IBAction func unwindToMyAppsViewController(_ segue: UIStoryboardSegue)
{
}
}
private extension MyAppsViewController
@@ -373,6 +379,21 @@ private extension MyAppsViewController
}
}
func fetchAppIDs()
{
AppManager.shared.fetchAppIDs { (result) in
do
{
let (_, context) = try result.get()
try context.save()
}
catch
{
print("Failed to fetch App IDs.", error)
}
}
}
func refresh(_ installedApps: [InstalledApp], completionHandler: @escaping (Result<[String : Result<InstalledApp, Error>], Error>) -> Void)
{
func refresh()
@@ -700,19 +721,6 @@ private extension MyAppsViewController
self.present(alertController, animated: true, completion: nil)
}
@IBAction func presentAppIDHelpAlert(_ sender: UIButton)
{
let message = NSLocalizedString("""
Each app and app extension installed with AltStore must register an App ID with Apple. Apple limits free developer accounts to 10 App IDs at a time.
App IDs expire after one week, but AltStore will automatically renew them for all installed apps. Once an App ID expires, it no longer counts toward your total.
""", comment: "")
let alertController = UIAlertController(title: NSLocalizedString("What are App IDs?", comment: ""), message: message, preferredStyle: .alert)
alertController.addAction(.ok)
self.present(alertController, animated: true, completion: nil)
}
}
private extension MyAppsViewController
@@ -843,24 +851,30 @@ extension MyAppsViewController
return headerView
case .installedApps:
let installedApps = self.installedAppsDataSource.fetchedResultsController.fetchedObjects ?? []
let registeredAppIDs = installedApps.filter { $0.team?.isActiveTeam ?? false }.reduce(0) { (sum, installedApp) in
// Each InstallApp has it's own app ID, plus one for each app extension.
return sum + 1 + installedApp.appExtensions.count
}
let maximumAppIDCount = 10
let remainingAppIDs = max(maximumAppIDCount - registeredAppIDs, 0)
let footerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "InstalledAppsFooter", for: indexPath) as! InstalledAppsCollectionFooterView
if remainingAppIDs == 1
guard let team = DatabaseManager.shared.activeTeam() else { return footerView }
switch team.type
{
footerView.textLabel.text = String(format: NSLocalizedString("1 App ID Remaining", comment: ""))
}
else
{
footerView.textLabel.text = String(format: NSLocalizedString("%@ App IDs Remaining", comment: ""), NSNumber(value: remainingAppIDs))
case .free:
let registeredAppIDs = team.appIDs.count
let maximumAppIDCount = 10
let remainingAppIDs = max(maximumAppIDCount - registeredAppIDs, 0)
if remainingAppIDs == 1
{
footerView.textLabel.text = String(format: NSLocalizedString("1 App ID Remaining", comment: ""))
}
else
{
footerView.textLabel.text = String(format: NSLocalizedString("%@ App IDs Remaining", comment: ""), NSNumber(value: remainingAppIDs))
}
footerView.textLabel.isHidden = false
case .individual, .organization, .unknown: footerView.textLabel.isHidden = true
@unknown default: break
}
return footerView
@@ -941,14 +955,15 @@ extension MyAppsViewController: UICollectionViewDelegateFlowLayout
case .updates: return .zero
case .installedApps:
#if BETA
if let team = DatabaseManager.shared.activeTeam(), team.type == .free
{
return CGSize(width: collectionView.bounds.width, height: 44)
}
else
{
return .zero
}
guard let _ = DatabaseManager.shared.activeTeam() else { return .zero }
let indexPath = IndexPath(row: 0, section: section.rawValue)
let footerView = self.collectionView(collectionView, viewForSupplementaryElementOfKind: UICollectionView.elementKindSectionFooter, at: indexPath) as! InstalledAppsCollectionFooterView
let size = footerView.systemLayoutSizeFitting(CGSize(width: collectionView.frame.width, height: UIView.layoutFittingExpandedSize.height),
withHorizontalFittingPriority: .required,
verticalFittingPriority: .fittingSizeLevel)
return size
#else
return .zero
#endif