From 04185917f4ce3974d73c36ad46293f83b1b59af6 Mon Sep 17 00:00:00 2001 From: thisisthekap Date: Mon, 19 Oct 2020 15:30:04 +0200 Subject: [PATCH] added ios extensions --- .../.idea/.gitignore | 13 +++ .../.idea/indexLayout.xml | 8 ++ .../.idea/misc.xml | 6 ++ .../.idea/riderModule.iml | 7 ++ .../.idea/vcs.xml | 6 ++ .../Exceptions/PurchasesErrorException.cs | 37 ++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++ .../PurchaseSuccessInfo.cs | 17 ++++ .../RCPurchasesExtensions.cs | 84 +++++++++++++++++++ .../Xamarin.RevenueCat.iOS.Extensions.csproj | 65 ++++++++++++++ .../azure-pipeline-public-nuget-publish.yml | 57 +++++++++++++ Xamarin.RevenueCat.iOS.sln | 26 ++++++ .../Xamarin.RevenueCat.iOS.csproj | 3 +- .../azure-pipeline-public-nuget-publish.yml | 6 +- 14 files changed, 367 insertions(+), 4 deletions(-) create mode 100644 .idea/.idea.Xamarin.RevenueCat.iOS/.idea/.gitignore create mode 100644 .idea/.idea.Xamarin.RevenueCat.iOS/.idea/indexLayout.xml create mode 100644 .idea/.idea.Xamarin.RevenueCat.iOS/.idea/misc.xml create mode 100644 .idea/.idea.Xamarin.RevenueCat.iOS/.idea/riderModule.iml create mode 100644 .idea/.idea.Xamarin.RevenueCat.iOS/.idea/vcs.xml create mode 100644 Xamarin.RevenueCat.iOS.Extensions/Exceptions/PurchasesErrorException.cs create mode 100644 Xamarin.RevenueCat.iOS.Extensions/Properties/AssemblyInfo.cs create mode 100644 Xamarin.RevenueCat.iOS.Extensions/PurchaseSuccessInfo.cs create mode 100644 Xamarin.RevenueCat.iOS.Extensions/RCPurchasesExtensions.cs create mode 100644 Xamarin.RevenueCat.iOS.Extensions/Xamarin.RevenueCat.iOS.Extensions.csproj create mode 100644 Xamarin.RevenueCat.iOS.Extensions/azure-pipeline-public-nuget-publish.yml diff --git a/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/.gitignore b/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/.gitignore new file mode 100644 index 0000000..a2ac9e2 --- /dev/null +++ b/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/contentModel.xml +/.idea.Xamarin.RevenueCat.iOS.iml +/projectSettingsUpdater.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/indexLayout.xml b/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/indexLayout.xml new file mode 100644 index 0000000..27ba142 --- /dev/null +++ b/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/misc.xml b/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/misc.xml new file mode 100644 index 0000000..1d8c84d --- /dev/null +++ b/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/riderModule.iml b/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/riderModule.iml new file mode 100644 index 0000000..1a4e0d9 --- /dev/null +++ b/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/riderModule.iml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/vcs.xml b/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.Xamarin.RevenueCat.iOS/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Xamarin.RevenueCat.iOS.Extensions/Exceptions/PurchasesErrorException.cs b/Xamarin.RevenueCat.iOS.Extensions/Exceptions/PurchasesErrorException.cs new file mode 100644 index 0000000..0873094 --- /dev/null +++ b/Xamarin.RevenueCat.iOS.Extensions/Exceptions/PurchasesErrorException.cs @@ -0,0 +1,37 @@ +using System; +using Foundation; +using Purchases; + +namespace Xamarin.RevenueCat.iOS.Extensions.Exceptions +{ + public class PurchasesErrorException : Exception + { + public NSError PurchasesError { get; } + public bool UserCancelled { get; } + + public NSObject ReadableErrorCode { get; } + public NSObject UnderlyingError { get; } + public string LocalizedDescription { get; } + public RCPurchasesErrorCode PurchasesErrorCode { get; } + + public PurchasesErrorException(NSError purchasesError, bool userCancelled) + : base($"{purchasesError?.Description} userCancelled: {userCancelled}") + { + PurchasesError = purchasesError; + UserCancelled = userCancelled; + if (purchasesError != null) + { + purchasesError.UserInfo.TryGetValue(RCPurchasesErrors.RCReadableErrorCodeKey, + out NSObject readableErrorCode); + ReadableErrorCode = readableErrorCode; + purchasesError.UserInfo.TryGetValue(NSError.UnderlyingErrorKey, out NSObject underlyingError); + UnderlyingError = underlyingError; + var localizedDescription = purchasesError.LocalizedDescription; + LocalizedDescription = localizedDescription; + + int purchaseErrorCodeInt = (int) purchasesError.Code; + PurchasesErrorCode = (RCPurchasesErrorCode) purchaseErrorCodeInt; + } + } + } +} diff --git a/Xamarin.RevenueCat.iOS.Extensions/Properties/AssemblyInfo.cs b/Xamarin.RevenueCat.iOS.Extensions/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e01f74a --- /dev/null +++ b/Xamarin.RevenueCat.iOS.Extensions/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Xamarin.RevenueCat.iOS.Extensions")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Xamarin.RevenueCat.iOS.Extensions")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("50c7b8c9-e664-45af-b88e-0c9b8b9c1be1")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Xamarin.RevenueCat.iOS.Extensions/PurchaseSuccessInfo.cs b/Xamarin.RevenueCat.iOS.Extensions/PurchaseSuccessInfo.cs new file mode 100644 index 0000000..a1c3c2f --- /dev/null +++ b/Xamarin.RevenueCat.iOS.Extensions/PurchaseSuccessInfo.cs @@ -0,0 +1,17 @@ +using Purchases; +using StoreKit; + +namespace Xamarin.RevenueCat.iOS.Extensions +{ + public class PurchaseSuccessInfo + { + public SKPaymentTransaction Transaction { get; } + public RCPurchaserInfo PurchaserInfo { get; } + + public PurchaseSuccessInfo(SKPaymentTransaction transaction, RCPurchaserInfo purchaserInfo) + { + Transaction = transaction; + PurchaserInfo = purchaserInfo; + } + } +} diff --git a/Xamarin.RevenueCat.iOS.Extensions/RCPurchasesExtensions.cs b/Xamarin.RevenueCat.iOS.Extensions/RCPurchasesExtensions.cs new file mode 100644 index 0000000..823cedc --- /dev/null +++ b/Xamarin.RevenueCat.iOS.Extensions/RCPurchasesExtensions.cs @@ -0,0 +1,84 @@ +using System.Threading; +using System.Threading.Tasks; +using Foundation; +using Purchases; +using StoreKit; +using Xamarin.RevenueCat.iOS.Extensions.Exceptions; + +namespace Xamarin.RevenueCat.iOS.Extensions +{ + public static class RCPurchasesExtensions + { + public static Task GetOfferingsAsync(this RCPurchases purchases, + CancellationToken cancellationToken = default) + { + var tcs = new TaskCompletionSource(); + cancellationToken.Register(() => tcs.TrySetCanceled()); + purchases.OfferingsWithCompletionBlock((RCOfferings offerings, NSError error) => + { + if (error != null) + { + tcs.TrySetException(new PurchasesErrorException(error, false)); + } + + tcs.TrySetResult(offerings); + }); + return tcs.Task; + } + + public static Task PurchasePackageAsync(this RCPurchases purchases, + RCPackage packageToPurchase, CancellationToken cancellationToken = default) + { + var tcs = new TaskCompletionSource(); + cancellationToken.Register(() => tcs.TrySetCanceled()); + purchases.PurchasePackage(packageToPurchase, + (SKPaymentTransaction transaction, RCPurchaserInfo purchaserInfo, NSError error, bool userCancelled) => + { + if (error != null) + { + tcs.TrySetException(new PurchasesErrorException(error, userCancelled)); + } + + if (userCancelled) + { + tcs.TrySetException(new PurchasesErrorException(null, true)); + } + + tcs.TrySetResult(new PurchaseSuccessInfo(transaction, purchaserInfo)); + }); + return tcs.Task; + } + + public static Task RestoreTransactionsAsync(this RCPurchases purchases, CancellationToken cancellationToken = default) + { + var tcs = new TaskCompletionSource(); + cancellationToken.Register(() => tcs.TrySetCanceled()); + purchases.RestoreTransactionsWithCompletionBlock((RCPurchaserInfo purchaserInfo, NSError error) => + { + if (error != null) + { + tcs.TrySetException(new PurchasesErrorException(error, false)); + } + + tcs.TrySetResult(purchaserInfo); + }); + return tcs.Task; + } + + public static Task GetPurchaserInfoAsync(this RCPurchases purchases, CancellationToken cancellationToken = default) + { + var tcs = new TaskCompletionSource(); + cancellationToken.Register(() => tcs.TrySetCanceled()); + purchases.PurchaserInfoWithCompletionBlock((RCPurchaserInfo purchaserInfo, NSError error) => + { + if (error != null) + { + tcs.TrySetException(new PurchasesErrorException(error, false)); + } + + tcs.TrySetResult(purchaserInfo); + }); + return tcs.Task; + } + } +} diff --git a/Xamarin.RevenueCat.iOS.Extensions/Xamarin.RevenueCat.iOS.Extensions.csproj b/Xamarin.RevenueCat.iOS.Extensions/Xamarin.RevenueCat.iOS.Extensions.csproj new file mode 100644 index 0000000..085a5b3 --- /dev/null +++ b/Xamarin.RevenueCat.iOS.Extensions/Xamarin.RevenueCat.iOS.Extensions.csproj @@ -0,0 +1,65 @@ + + + + true + Xamarin.RevenueCat.iOS.Extensions + Contains convenience methods and async extensions for Xamarin.RevenueCat.iOS + 3.5.3.5 + Christian Kapplmüller + fun.music IT GmbH + nugetoutput + ..\..\..\LICENSE.txt + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {9774C184-1A52-40A3-82F7-3D27F92AD38E} + {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {a52b8a63-bc84-4b47-910d-692533484892} + Library + Xamarin.RevenueCat.iOS.Extensions + Resources + Xamarin.RevenueCat.iOS.Extensions + PackageReference + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + + + full + true + bin\Release + prompt + 4 + + + + + + + + + + + + + + + + + + + {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA} + Xamarin.RevenueCat.iOS + + + + \ No newline at end of file diff --git a/Xamarin.RevenueCat.iOS.Extensions/azure-pipeline-public-nuget-publish.yml b/Xamarin.RevenueCat.iOS.Extensions/azure-pipeline-public-nuget-publish.yml new file mode 100644 index 0000000..d059ba1 --- /dev/null +++ b/Xamarin.RevenueCat.iOS.Extensions/azure-pipeline-public-nuget-publish.yml @@ -0,0 +1,57 @@ +trigger: + branches: + include: + - refs/tags/release-extensions-v* + +pool: + vmImage: 'macOS-10.15' + +variables: + - group: tonestro.private.artifacts + +steps: + +- bash: | + echo "##vso[task.setvariable variable=bindingsVersion]$(cat Xamarin.RevenueCat.iOS/Xamarin.RevenueCat.iOS.csproj | grep '' | awk -F '[<>]' '{print $3}')" + +- bash: | + echo "##vso[build.updatebuildnumber]xamarin-revenuecat-ios-extensions-$(Build.SourceBranchName)-$(Build.BuildId)" + +- bash: | + if [[ "$(Build.SourceBranchName)" != *"$(bindingsVersion)" ]]; then + echo "mismatch between tag $(Build.SourceBranchName) and nuget version $(bindingsVersion)" + exit 1 + fi + +- bash: | + cd Xamarin.RevenueCat.iOS.Extensions + msbuild /t:Restore /p:Configuration=Release + msbuild /t:Build /p:Configuration=Release + msbuild /t:Pack /p:Configuration=Release + +- task: NuGetAuthenticate@0 + displayName: 'NuGet Authenticate' +- task: NuGetCommand@2 + displayName: 'NuGet push' + inputs: + command: 'push' + packagesToPush: 'Xamarin.RevenueCat.iOS.Extensions/nugetoutput/Xamarin.RevenueCat.iOS.Extensions.*.nupkg' + nuGetFeedType: 'internal' + publishVstsFeed: '95a4928e-7a26-4e37-a11b-e681e1d9910c' + allowPackageConflicts: true + +#- bash: | +# dotnet nuget push Xamarin.RevenueCat.iOS.Extensions/nugetoutput/Xamarin.RevenueCat.iOS.Extensions.*.nupkg -k "$(azureDevOpsRepoApiKey)" -s "$(azureDevOpsRepoTargetUrl)" + +#- task: GitHubRelease@1 +# inputs: +# gitHubConnection: 'github.com_thisisthekap' +# repositoryName: 'thisisthekap/Xamarin.RevenueCat.iOS' +# action: 'create' +# target: '$(Build.SourceVersion)' +# tagSource: 'userSpecifiedTag' +# tag: '$(Build.SourceBranchName)' +# title: 'Xamarin.RevenueCat.iOS.Extensions $(bindingsVersion)' +# assets: 'Xamarin.RevenueCat.iOS.Extensions/nugetoutput/Xamarin.RevenueCat.iOS.Extensions.*.nupkg' +# changeLogCompareToRelease: 'lastFullRelease' +# changeLogType: 'issueBased' diff --git a/Xamarin.RevenueCat.iOS.sln b/Xamarin.RevenueCat.iOS.sln index ed000e0..c481c7d 100644 --- a/Xamarin.RevenueCat.iOS.sln +++ b/Xamarin.RevenueCat.iOS.sln @@ -5,16 +5,42 @@ VisualStudioVersion = 16.0.808.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.RevenueCat.iOS", "Xamarin.RevenueCat.iOS\Xamarin.RevenueCat.iOS.csproj", "{EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.RevenueCat.iOS.Extensions", "Xamarin.RevenueCat.iOS.Extensions\Xamarin.RevenueCat.iOS.Extensions.csproj", "{9774C184-1A52-40A3-82F7-3D27F92AD38E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU + Debug|iPhoneSimulator = Debug|iPhoneSimulator + Release|iPhoneSimulator = Release|iPhoneSimulator + Debug|iPhone = Debug|iPhone + Release|iPhone = Release|iPhone EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Debug|Any CPU.Build.0 = Debug|Any CPU {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Release|Any CPU.ActiveCfg = Release|Any CPU {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Release|Any CPU.Build.0 = Release|Any CPU + {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Debug|iPhone.Build.0 = Debug|Any CPU + {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Release|iPhone.ActiveCfg = Release|Any CPU + {EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}.Release|iPhone.Build.0 = Release|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Release|Any CPU.Build.0 = Release|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Debug|iPhone.Build.0 = Debug|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Release|iPhone.ActiveCfg = Release|Any CPU + {9774C184-1A52-40A3-82F7-3D27F92AD38E}.Release|iPhone.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Xamarin.RevenueCat.iOS/Xamarin.RevenueCat.iOS.csproj b/Xamarin.RevenueCat.iOS/Xamarin.RevenueCat.iOS.csproj index 3582037..d564bec 100644 --- a/Xamarin.RevenueCat.iOS/Xamarin.RevenueCat.iOS.csproj +++ b/Xamarin.RevenueCat.iOS/Xamarin.RevenueCat.iOS.csproj @@ -3,7 +3,8 @@ true Xamarin.RevenueCat.iOS - 1.1.2 + 3.5.3.5 + Contains bindings for https://docs.revenuecat.com/docs/ios Christian Kapplmüller fun.music IT GmbH nugetoutput diff --git a/Xamarin.RevenueCat.iOS/azure-pipeline-public-nuget-publish.yml b/Xamarin.RevenueCat.iOS/azure-pipeline-public-nuget-publish.yml index f64a736..5843fd1 100644 --- a/Xamarin.RevenueCat.iOS/azure-pipeline-public-nuget-publish.yml +++ b/Xamarin.RevenueCat.iOS/azure-pipeline-public-nuget-publish.yml @@ -1,7 +1,7 @@ trigger: branches: include: - - refs/tags/release-v* + - refs/tags/release-bindings-v* pool: vmImage: 'macOS-10.15' @@ -15,7 +15,7 @@ steps: echo "##vso[task.setvariable variable=bindingsVersion]$(cat Xamarin.RevenueCat.iOS/Xamarin.RevenueCat.iOS.csproj | grep '' | awk -F '[<>]' '{print $3}')" - bash: | - echo "##vso[build.updatebuildnumber]xamarin-revenuecat-ios-$(Build.SourceBranchName)-$(Build.BuildId)" + echo "##vso[build.updatebuildnumber]xamarin-revenuecat-ios-bindings-$(Build.SourceBranchName)-$(Build.BuildId)" - bash: | if [[ "$(Build.SourceBranchName)" != *"$(bindingsVersion)" ]]; then @@ -51,7 +51,7 @@ steps: # target: '$(Build.SourceVersion)' # tagSource: 'userSpecifiedTag' # tag: '$(Build.SourceBranchName)' -# title: 'Xamarin.RevenueCat.iOS $(bindingsVersion)' +# title: 'Xamarin.RevenueCat.iOS Bindings $(bindingsVersion)' # assets: 'Xamarin.RevenueCat.iOS/nugetoutput/Xamarin.RevenueCat.iOS.*.nupkg' # changeLogCompareToRelease: 'lastFullRelease' # changeLogType: 'issueBased'