Skip to content

Commit

Permalink
[feature/appstore-buildflag] Remove App Store / IAP code via build fl…
Browse files Browse the repository at this point in the history
…ag (#1052)

* - add support and documentation for DISABLE_APPSTORE_LICENSING build flag

* - ReleaseNotesHostViewController: remove unused reference to StoreKit
- OCLicenseDuration: make sure SKProductSubscriptionPeriod conversion code is excluded when using the DISABLE_APPSTORE_LICENSING build flag
  • Loading branch information
felix-schwarz authored Nov 17, 2021
1 parent 4e29fd5 commit 2b6a83d
Show file tree
Hide file tree
Showing 25 changed files with 91 additions and 2 deletions.
6 changes: 6 additions & 0 deletions doc/APP_BUILD_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ Removes the following from the app:
- the location description keys from the app's `Info.plist`

Not used by default.

### `DISABLE_APPSTORE_LICENSING`

Removes the following from the app:
- App Store integration for OCLicense
- App Store related view controllers and settings section
2 changes: 2 additions & 0 deletions ownCloud/Client/Actions/Action+UserInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ extension Action {
if !isLicensed {
if let core = core, let requirements = type(of:self).licenseRequirements {
OnMainThread {
#if !DISABLE_APPSTORE_LICENSING
OCLicenseManager.appStoreProvider?.refreshProductsIfNeeded(completionHandler: { (error) in
OnMainThread {
if error != nil {
Expand All @@ -107,6 +108,7 @@ extension Action {
}
}
})
#endif
}
}

Expand Down
4 changes: 4 additions & 0 deletions ownCloud/Licensing/Offers/LicenseOfferButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#if !DISABLE_APPSTORE_LICENSING

import UIKit
import ownCloudAppShared

Expand Down Expand Up @@ -61,3 +63,5 @@ class LicenseOfferButton: ThemeButton {
fatalError("init(coder:) has not been implemented")
}
}

#endif
4 changes: 4 additions & 0 deletions ownCloud/Licensing/Offers/LicenseOfferView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#if !DISABLE_APPSTORE_LICENSING

import UIKit
import ownCloudApp
import ownCloudAppShared
Expand Down Expand Up @@ -288,3 +290,5 @@ class LicenseOfferView: UIView, Themeable {
}
}
}

#endif
6 changes: 6 additions & 0 deletions ownCloud/Licensing/Offers/LicenseOffersViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#if !DISABLE_APPSTORE_LICENSING

import UIKit
import ownCloudApp
import ownCloudAppShared
Expand Down Expand Up @@ -116,6 +118,7 @@ class LicenseOffersViewController: StaticTableViewController {
sections.append(subSection)
}

#if !DISABLE_APPSTORE_LICENSING
let restoreSection = StaticTableViewSection()

restoreSection.add(row: StaticTableViewRow(rowWithAction: { (_, _) in
Expand All @@ -125,6 +128,7 @@ class LicenseOffersViewController: StaticTableViewController {
}, title: "Restore purchases".localized, alignment: .center))

sections.append(restoreSection)
#endif

// Set sections
self.sections = sections
Expand Down Expand Up @@ -153,3 +157,5 @@ class LicenseOffersViewController: StaticTableViewController {
self.tableView.contentInsetAdjustmentBehavior = .never
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#if !DISABLE_APPSTORE_LICENSING

import UIKit
import ownCloudApp
import ownCloudAppShared
Expand Down Expand Up @@ -132,3 +134,5 @@ class LicenseInAppProductListViewController: StaticTableViewController {
}

}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#if !DISABLE_APPSTORE_LICENSING

import UIKit
import ownCloudApp
import ownCloudAppShared
Expand Down Expand Up @@ -134,3 +136,5 @@ class LicenseInAppPurchaseFeatureView: UIView, Themeable {
baseViewController?.present(asCard: FrameViewController(header: offersViewController.cardHeaderView!, viewController: offersViewController), animated: true)
}
}

#endif
5 changes: 4 additions & 1 deletion ownCloud/Licensing/Tools/OCLicenseManager+AppStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#if !DISABLE_APPSTORE_LICENSING

import UIKit
import ownCloudApp
import ownCloudAppShared
Expand Down Expand Up @@ -52,5 +54,6 @@ extension OCLicenseManager {
})
}
}

}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#if !DISABLE_APPSTORE_LICENSING

import UIKit
import ownCloudApp
import ownCloudAppShared
Expand Down Expand Up @@ -111,3 +113,5 @@ class LicenseTransactionsViewController: StaticTableViewController {
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import UIKit
import ownCloudSDK
import ownCloudAppShared
import StoreKit

class ReleaseNotesHostViewController: UIViewController {

Expand Down
2 changes: 2 additions & 0 deletions ownCloud/Settings/PurchasesSettingsSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import UIKit
import ownCloudApp
import ownCloudAppShared

#if !DISABLE_APPSTORE_LICENSING
class PurchasesSettingsSection: SettingsSection {
// MARK: - More Settings Cells

Expand Down Expand Up @@ -62,3 +63,4 @@ class PurchasesSettingsSection: SettingsSection {
add(rows: rows)
}
}
#endif
2 changes: 2 additions & 0 deletions ownCloud/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ class SettingsViewController: StaticTableViewController {
self.addSection(DisplaySettingsSection(userDefaults: userDefaults))
self.addSection(MediaFilesSettingsSection(userDefaults: userDefaults))

#if !DISABLE_APPSTORE_LICENSING
if #available(iOS 13, *), // Require iOS 13
!OCLicenseEMMProvider.isEMMVersion, // Do not show purchases in the EMM version
// Do only show purchases section if there's at least one non-Enterprise account
OCLicenseEnterpriseProvider.numberOfEnterpriseAccounts < OCBookmarkManager.shared.bookmarks.count, !VendorServices.shared.isBranded // Do not show purchases in branded app
{
self.addSection(PurchasesSettingsSection(userDefaults: userDefaults))
}
#endif

self.addSection(MoreSettingsSection(userDefaults: userDefaults))
}
Expand Down
5 changes: 5 additions & 0 deletions ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
*/

#import <Foundation/Foundation.h>

#ifndef DISABLE_APPSTORE_LICENSING
#import <StoreKit/StoreKit.h>
#endif /* DISABLE_APPSTORE_LICENSING */

typedef NS_ENUM(NSUInteger, OCLicenseDurationUnit)
{
Expand Down Expand Up @@ -48,10 +51,12 @@ NS_ASSUME_NONNULL_BEGIN

@end

#ifndef DISABLE_APPSTORE_LICENSING
@interface SKProductSubscriptionPeriod (OCLicenseDuration)

@property(readonly,nonatomic,nullable) OCLicenseDuration *licenseDuration;

@end
#endif /* DISABLE_APPSTORE_LICENSING */

NS_ASSUME_NONNULL_END
3 changes: 3 additions & 0 deletions ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ - (NSDate *)dateWithDurationAddedTo:(NSDate *)date

@end

#ifndef DISABLE_APPSTORE_LICENSING

@implementation SKProductSubscriptionPeriod (OCLicenseDuration)

Expand Down Expand Up @@ -226,3 +227,5 @@ - (nullable OCLicenseDuration *)licenseDuration
}

@end

#endif /* DISABLE_APPSTORE_LICENSING */
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#ifndef DISABLE_APPSTORE_LICENSING

#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>
#import "OCLicenseOffer.h"
Expand Down Expand Up @@ -47,3 +49,5 @@ typedef NSString* OCLicenseAppStoreProductIdentifier;
@end

NS_ASSUME_NONNULL_END

#endif /* DISABLE_APPSTORE_LICENSING */
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#ifndef DISABLE_APPSTORE_LICENSING

#import "OCLicenseAppStoreItem.h"

@implementation OCLicenseAppStoreItem
Expand Down Expand Up @@ -50,3 +52,5 @@ - (instancetype)initWithType:(OCLicenseType)type identifier:(OCLicenseAppStorePr
}

@end

#endif /* DISABLE_APPSTORE_LICENSING */
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#ifndef DISABLE_APPSTORE_LICENSING

#import <ownCloudSDK/ownCloudSDK.h>

#import "OCLicenseProvider.h"
Expand Down Expand Up @@ -70,3 +72,4 @@ extern NSErrorDomain OCLicenseAppStoreProviderErrorDomain;

NS_ASSUME_NONNULL_END

#endif /* DISABLE_APPSTORE_LICENSING */
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#ifndef DISABLE_APPSTORE_LICENSING

#import <StoreKit/StoreKit.h>
#import <ownCloudSDK/ownCloudSDK.h>

Expand Down Expand Up @@ -936,3 +938,5 @@ + (OCLicenseAppStoreProvider *)appStoreProvider
OCLicenseProviderIdentifier OCLicenseProviderIdentifierAppStore = @"app-store";

NSErrorDomain OCLicenseAppStoreProviderErrorDomain = @"OCLicenseAppStoreProviderError";

#endif /* DISABLE_APPSTORE_LICENSING */
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#ifndef DISABLE_APPSTORE_LICENSING

#import <Foundation/Foundation.h>
#import "OCLicenseAppStoreReceipt.h"

Expand All @@ -39,3 +41,5 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END

#endif /* DISABLE_APPSTORE_LICENSING */
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#ifndef DISABLE_APPSTORE_LICENSING

#import "OCASN1.h"
#import "NSDate+RFC3339.h"

Expand Down Expand Up @@ -217,3 +219,5 @@ - (OCLicenseAppStoreReceiptParseError)parseSetsOfSequencesWithContainerProvider:
}

@end

#endif /* DISABLE_APPSTORE_LICENSING */
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#ifndef DISABLE_APPSTORE_LICENSING

#import <Foundation/Foundation.h>
#import "OCLicenseAppStoreItem.h"

Expand Down Expand Up @@ -105,3 +107,5 @@ typedef NSNumber* OCLicenseAppStoreLineItemID;
NS_ASSUME_NONNULL_END

#import "OCLicenseAppStoreReceiptInAppPurchase.h"

#endif /* DISABLE_APPSTORE_LICENSING */
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#ifndef DISABLE_APPSTORE_LICENSING

#import <UIKit/UIKit.h>
#import <ownCloudSDK/ownCloudSDK.h>

Expand Down Expand Up @@ -243,3 +245,5 @@ - (NSString *)description
}

@end

#endif /* DISABLE_APPSTORE_LICENSING */
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#ifndef DISABLE_APPSTORE_LICENSING

#import <Foundation/Foundation.h>
#import "OCLicenseAppStoreReceipt.h"

Expand Down Expand Up @@ -46,3 +48,5 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END

#endif /* DISABLE_APPSTORE_LICENSING */
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

#ifndef DISABLE_APPSTORE_LICENSING

#import "OCLicenseAppStoreReceiptInAppPurchase.h"
#import "OCASN1.h"

Expand Down Expand Up @@ -78,3 +80,5 @@ - (NSString *)description
}

@end

#endif /* DISABLE_APPSTORE_LICENSING */
2 changes: 2 additions & 0 deletions ownCloudAppShared/Intent/OCLicenseManager+Setup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public extension OCLicenseManager {
register(OCLicenseProduct(identifier: .bundlePro, name: "Pro Features".localized, description: "Unlock all Pro Features.".localized, contents: [.documentScanner, .shortcuts, .documentMarkup, .photoProFeatures]))

// Set up App Store License Provider
#if !DISABLE_APPSTORE_LICENSING
if let disableAppStoreLicensing = classSetting(forOCClassSettingsKey: .disableAppStoreLicensing) as? Bool, disableAppStoreLicensing == false, // only add AppStore IAP provider (and IAPs) if IAP licernsing has not been disabled via ClassSettings
!OCLicenseEMMProvider.isEMMVersion { // only add AppStore IAP provider (and IAPs) if this is not the EMM version (which is supposed to already include all of them)
let appStoreLicenseProvider = OCLicenseAppStoreProvider(items: [
Expand All @@ -78,6 +79,7 @@ public extension OCLicenseManager {

add(appStoreLicenseProvider)
}
#endif

// Set up Enterprise Provider
if let disableEnterpriseLicensing = classSetting(forOCClassSettingsKey: .disableEnterpriseLicensing) as? Bool, disableEnterpriseLicensing == false { // only add Enterprise provider if not disabled via ClassSettings
Expand Down

0 comments on commit 2b6a83d

Please sign in to comment.