Skip to content

Commit

Permalink
Merge pull request #3 from thisisthekap/br_2_add_ios_extensions
Browse files Browse the repository at this point in the history
added ios extensions
  • Loading branch information
thisisthekap authored Oct 19, 2020
2 parents acffea5 + 0418591 commit 70e1369
Show file tree
Hide file tree
Showing 14 changed files with 367 additions and 4 deletions.
13 changes: 13 additions & 0 deletions .idea/.idea.Xamarin.RevenueCat.iOS/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.Xamarin.RevenueCat.iOS/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.Xamarin.RevenueCat.iOS/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/.idea.Xamarin.RevenueCat.iOS/.idea/riderModule.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.Xamarin.RevenueCat.iOS/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
36 changes: 36 additions & 0 deletions Xamarin.RevenueCat.iOS.Extensions/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
17 changes: 17 additions & 0 deletions Xamarin.RevenueCat.iOS.Extensions/PurchaseSuccessInfo.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
84 changes: 84 additions & 0 deletions Xamarin.RevenueCat.iOS.Extensions/RCPurchasesExtensions.cs
Original file line number Diff line number Diff line change
@@ -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<RCOfferings> GetOfferingsAsync(this RCPurchases purchases,
CancellationToken cancellationToken = default)
{
var tcs = new TaskCompletionSource<RCOfferings>();
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<PurchaseSuccessInfo> PurchasePackageAsync(this RCPurchases purchases,
RCPackage packageToPurchase, CancellationToken cancellationToken = default)
{
var tcs = new TaskCompletionSource<PurchaseSuccessInfo>();
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<RCPurchaserInfo> RestoreTransactionsAsync(this RCPurchases purchases, CancellationToken cancellationToken = default)
{
var tcs = new TaskCompletionSource<RCPurchaserInfo>();
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<RCPurchaserInfo> GetPurchaserInfoAsync(this RCPurchases purchases, CancellationToken cancellationToken = default)
{
var tcs = new TaskCompletionSource<RCPurchaserInfo>();
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;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageId>Xamarin.RevenueCat.iOS.Extensions</PackageId>
<Description>Contains convenience methods and async extensions for Xamarin.RevenueCat.iOS</Description>
<Version>3.5.3.5</Version>
<Authors>Christian Kapplmüller</Authors>
<Company>fun.music IT GmbH</Company>
<PackageOutputPath>nugetoutput</PackageOutputPath>
<PackageLicensePath>..\..\..\LICENSE.txt</PackageLicensePath>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9774C184-1A52-40A3-82F7-3D27F92AD38E}</ProjectGuid>
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TemplateGuid>{a52b8a63-bc84-4b47-910d-692533484892}</TemplateGuid>
<OutputType>Library</OutputType>
<RootNamespace>Xamarin.RevenueCat.iOS.Extensions</RootNamespace>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
<AssemblyName>Xamarin.RevenueCat.iOS.Extensions</AssemblyName>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<Compile Include="RCPurchasesExtensions.cs" />
<Compile Include="Exceptions\PurchasesErrorException.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PurchaseSuccessInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="5.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Xamarin.RevenueCat.iOS\Xamarin.RevenueCat.iOS.csproj">
<Project>{EAA9C04E-CFAD-49D2-A3A8-168A811D79DA}</Project>
<Name>Xamarin.RevenueCat.iOS</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -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 '<Version>' | 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'
26 changes: 26 additions & 0 deletions Xamarin.RevenueCat.iOS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 70e1369

Please sign in to comment.