-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: manage subscriptions modal #532
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3c6ab88
added new public-facing swift framework that imports purchases and ex…
aboedo cdf3b91
updated settings for PurchasesSwift to match Purchases
aboedo 0ae0f80
added initial crude implementation for openManageSubscriptions
aboedo d6d8c14
added initial crude implementation for openManageSubscriptions
aboedo c7aabb7
improved logic for manageSubscriptions to show the iOS settings if us…
aboedo 9c1f9b0
added PurchasesSwift podspec
aboedo 01792f8
add platform check for new methods, since they only work on iOS
aboedo f5109dd
added SPM target for PurchasesSwift
aboedo 55b9e7b
cleaned up package.swift
aboedo 6e0782c
added macOS compatibility with manage subscriptions modal
aboedo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Pod::Spec.new do |s| | ||
s.name = "PurchasesSwift" | ||
s.version = "3.12.0-SNAPSHOT" | ||
s.summary = "Subscription and in-app-purchase backend service." | ||
|
||
s.description = <<-DESC | ||
Save yourself the hastle of implementing a subscriptions backend. Use RevenueCat instead https://www.revenuecat.com/ | ||
DESC | ||
|
||
s.homepage = "https://www.revenuecat.com/" | ||
s.license = { :type => 'MIT' } | ||
s.author = { "RevenueCat, Inc." => "support@revenuecat.com" } | ||
s.source = { :git => "https://github.com/revenuecat/purchases-ios.git", :tag => s.version.to_s } | ||
s.documentation_url = "https://docs.revenuecat.com/" | ||
|
||
s.framework = 'StoreKit' | ||
s.swift_version = '5.0' | ||
|
||
s.ios.deployment_target = '9.0' | ||
s.osx.deployment_target = '10.12' | ||
s.watchos.deployment_target = '6.2' | ||
s.tvos.deployment_target = '9.0' | ||
|
||
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } | ||
s.dependency 'Purchases', '3.12.0-SNAPSHOT' | ||
|
||
s.source_files = ['PurchasesSwift/**/*.{swift}'] | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# ``PurchasesSwift`` | ||
|
||
<!--@START_MENU_TOKEN@-->Summary<!--@END_MENU_TOKEN@--> | ||
|
||
## Overview | ||
|
||
<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@--> | ||
|
||
## Topics | ||
|
||
### <!--@START_MENU_TOKEN@-->Group<!--@END_MENU_TOKEN@--> | ||
|
||
- <!--@START_MENU_TOKEN@-->``Symbol``<!--@END_MENU_TOKEN@--> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// PurchasesSwift.h | ||
// PurchasesSwift | ||
// | ||
// Created by Andrés Boedo on 6/16/21. | ||
// Copyright © 2021 Purchases. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
//! Project version number for PurchasesSwift. | ||
FOUNDATION_EXPORT double PurchasesSwiftVersionNumber; | ||
|
||
//! Project version string for PurchasesSwift. | ||
FOUNDATION_EXPORT const unsigned char PurchasesSwiftVersionString[]; | ||
|
||
// In this header, you should import all the public headers of your framework using statements like #import <PurchasesSwift/PublicHeader.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// PurchasesSwift.swift | ||
// PurchasesSwift | ||
// | ||
// Created by Andrés Boedo on 6/16/21. | ||
// Copyright © 2021 Purchases. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import StoreKit | ||
|
||
@_exported import Purchases | ||
|
||
|
||
@objc public extension Purchases { | ||
@objc func showManageSubscriptionModal() { | ||
|
||
self.purchaserInfo { purchaserInfo, error in | ||
if let error = error { | ||
print("there was an error getting purchaserInfo: \(error.localizedDescription)") | ||
return | ||
} | ||
|
||
guard let purchaserInfo = purchaserInfo else { | ||
print("there was no error but purchaserInfo is null!") | ||
return | ||
} | ||
|
||
guard let managementURL = purchaserInfo.managementURL else { | ||
print("managementURL is nil, opening iOS subscription management page") | ||
self.showAppleManageSubscriptions() | ||
return | ||
} | ||
|
||
#if os(iOS) | ||
if managementURL.isAppleSubscription() { | ||
if #available(iOS 15.0, *) { | ||
detach { | ||
await self.showSK2ManageSubscriptions() | ||
} | ||
} | ||
return | ||
} | ||
#endif | ||
self.openURL(managementURL) | ||
} | ||
} | ||
} | ||
|
||
public extension Purchases { | ||
|
||
@available(iOS 9.0, *) | ||
@available(macOS 10.12, *) | ||
@available(watchOS, unavailable) | ||
@available(tvOS, unavailable) | ||
func showAppleManageSubscriptions() { | ||
#if os(iOS) | ||
if #available(iOS 15.0, *) { | ||
detach { | ||
await self.showSK2ManageSubscriptions() | ||
} | ||
} else { | ||
self.openURL(.appleSubscriptionsURL) | ||
} | ||
#elseif os(macOS) | ||
self.openURL(.appleSubscriptionsURL) | ||
#endif | ||
} | ||
|
||
@MainActor | ||
@available(iOS 15.0, *) | ||
@available(macOS, unavailable) | ||
@available(watchOS, unavailable) | ||
@available(tvOS, unavailable) | ||
func showSK2ManageSubscriptions() async { | ||
#if os(iOS) | ||
let windowScene = UIApplication.shared | ||
.connectedScenes | ||
.filter { $0.activationState == .foregroundActive } | ||
.first | ||
|
||
if let windowScene = windowScene as? UIWindowScene { | ||
|
||
do { | ||
try await AppStore.showManageSubscriptions(in: windowScene) | ||
} catch let error { | ||
print("error when trying to show manage subscription: \(error.localizedDescription)") | ||
} | ||
} else { | ||
print("couldn't get window") | ||
} | ||
#endif | ||
} | ||
|
||
func openURL(_ url: URL) { | ||
#if os(iOS) | ||
if #available(iOS 10.0, *) { | ||
UIApplication.shared.open(url) | ||
} else { | ||
UIApplication.shared.openURL(url) | ||
} | ||
#elseif os(macOS) | ||
NSWorkspace.shared.open(url) | ||
#endif | ||
} | ||
} | ||
|
||
private extension URL { | ||
func isAppleSubscription() -> Bool { | ||
self.absoluteString.contains("apps.apple.com") | ||
} | ||
|
||
static let appleSubscriptionsURL = URL(string: "https://apps.apple.com/account/subscriptions")! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// PurchasesSwiftTests.swift | ||
// PurchasesSwiftTests | ||
// | ||
// Created by Andrés Boedo on 6/16/21. | ||
// Copyright © 2021 Purchases. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import PurchasesSwift | ||
|
||
class PurchasesSwiftTests: XCTestCase { | ||
|
||
override func setUpWithError() throws { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
func testExample() throws { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct results. | ||
} | ||
|
||
func testPerformanceExample() throws { | ||
// This is an example of a performance test case. | ||
self.measure { | ||
// Put the code you want to measure the time of here. | ||
} | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it potentially be possible to batch these into a single custom annotation? i can see us repeating these lines alllll over the place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'd be able to do it at the extension declaration level, and it'd apply to everything in it.