Skip to content

Commit

Permalink
Merge pull request #17 from thisisthekap/br_16_update_binding_to_4-1-0
Browse files Browse the repository at this point in the history
updated binding to 4.1.0
  • Loading branch information
thisisthekap authored Mar 30, 2022
2 parents 1c6c51b + 69ba176 commit 31b6018
Show file tree
Hide file tree
Showing 45 changed files with 11,526 additions and 852 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,4 @@ MigrationBackup/

# End of https://www.toptal.com/developers/gitignore/api/visualstudio

.DS_Store
2 changes: 1 addition & 1 deletion .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.

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

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 fun.music IT GmbH
Copyright (c) 2022 fun.music IT GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
41 changes: 0 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,6 @@ Add `-gcc_flags "-ObjC"` to the `MtouchExtraArgs` XML element of your project fi

Please see [this issue](https://github.com/thisisthekap/Xamarin.RevenueCat.iOS/issues/13) for more details.

## How to bind new version

This section explains how to create resp. adapt the bindings to bind to a newer version of RevenueCat for iOS.

### Build static library

1. `cd sharpie`
2. Set the desired version of RevenueCat for iOS in `revenuecat-version.txt`
3. Execute `./prepare-library-build.sh`
4. Right click "Purchases" to add files:
* ![howto-1](readme-images/howto-1.png)
5. Select everything in the "Purchases" folder, and make sure that the settings are configured as described:
* ![howto-2](readme-images/howto-2.png)
6. Press "Add"
7. Close XCode
8. Execute `./finish-library-build.sh`

After these steps, a new static library was built and moved to `Xamarin.RevenueCat.iOS/nativelib/libPurchases.a`. This file is referenced as `NativeReference` in `Xamarin.RevenueCat.iOS.csproj`.

### Create C# Bindings using Objective Sharpie

This section describes how to create `ApiBindings.cs` and `StructsAndEnums.cs`.

1. `cd sharpie`
2. Set the desired version of RevenueCat for iOS in `revenuecat-version.txt`
3. Execute `./create-sharpie-files.sh`
4. Copy `ApiBindings.cs` and `StructsAndEnums.cs` to `../Xamarin.RevenueCat.iOS`

#### Tip when updating to newer version of revenuecat/purchases-ios

To find out which API changes were made between two versions of revenuecat/purchases-ios, you could execute sharpie twice:

1. Execute steps 1 to 3 from the steps above
* Do not change the version of `revenuecat/purchases-ios` in `revenuecat-version.txt`
2. Execute `mv ApiBindings.cs ApiBindings_old.cs`
3. Execute `mv StructsAndEnums.cs StructsAndEnums_old.cs`
4. Change the version of `revenuecat/purchases-ios` in `revenuecat-version.txt`
5. Execute `./create-sharpie-files.sh`

Now you can use `diff` or your favorite diff tool to detect the changes between both versions.

## License

The license for this repository is specified in
Expand Down
16 changes: 16 additions & 0 deletions Xamarin.RevenueCat.iOS.Extensions/LoginResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using RevenueCat;

namespace Xamarin.RevenueCat.iOS.Extensions
{
public struct LoginResult
{
public RCCustomerInfo CustomerInfo { get; }
public bool Created { get; }

public LoginResult(RCCustomerInfo customerInfo, bool created)
{
CustomerInfo = customerInfo;
Created = created;
}
}
}
13 changes: 6 additions & 7 deletions Xamarin.RevenueCat.iOS.Extensions/PurchaseSuccessInfo.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using Purchases;
using StoreKit;
using RevenueCat;

namespace Xamarin.RevenueCat.iOS.Extensions
{
public class PurchaseSuccessInfo
public struct PurchaseSuccessInfo
{
public SKPaymentTransaction Transaction { get; }
public RCPurchaserInfo PurchaserInfo { get; }
public RCStoreTransaction Transaction { get; }
public RCCustomerInfo CustomerInfo { get; }

public PurchaseSuccessInfo(SKPaymentTransaction transaction, RCPurchaserInfo purchaserInfo)
public PurchaseSuccessInfo(RCStoreTransaction transaction, RCCustomerInfo customerInfo)
{
Transaction = transaction;
PurchaserInfo = purchaserInfo;
CustomerInfo = customerInfo;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using Foundation;
using Purchases;
using RevenueCat;

namespace Xamarin.RevenueCat.iOS.Extensions.Exceptions
namespace Xamarin.RevenueCat.iOS.Extensions
{
public class PurchasesErrorException : Exception
{
Expand All @@ -15,22 +15,22 @@ public class PurchasesErrorException : Exception
public RCPurchasesErrorCode PurchasesErrorCode { get; }

public PurchasesErrorException(NSError purchasesError, bool userCancelled)
: base($"{purchasesError?.Description} userCancelled: {userCancelled}")
: base($"{purchasesError?.Description} userCancelled: {userCancelled}",
new NSErrorException(purchasesError))
{
PurchasesError = purchasesError;
UserCancelled = userCancelled;
if (purchasesError != null)
{
purchasesError.UserInfo.TryGetValue(RCPurchasesErrors.RCReadableErrorCodeKey,
out NSObject readableErrorCode);
purchasesError.UserInfo.TryGetValue(ErrorDetails.ReadableErrorCodeKey, 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;
int purchaseErrorCodeInt = (int)purchasesError.Code;
PurchasesErrorCode = (RCPurchasesErrorCode)purchaseErrorCodeInt;
}
}
}
Expand Down
35 changes: 17 additions & 18 deletions Xamarin.RevenueCat.iOS.Extensions/RCPurchasesExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
using System.Threading;
using System.Threading.Tasks;
using Foundation;
using Purchases;
using StoreKit;
using Xamarin.RevenueCat.iOS.Extensions.Exceptions;
using RevenueCat;

namespace Xamarin.RevenueCat.iOS.Extensions
{
// ReSharper disable once InconsistentNaming
public static class RCPurchasesExtensions
{
public static Task<RCPurchaserInfo> IdentifyAsync(this RCPurchases purchases, string appUserId,
public static Task<LoginResult> LoginAsync(this RCPurchases purchases, string appUserId,
CancellationToken cancellationToken = default)
{
var tcs = new TaskCompletionSource<RCPurchaserInfo>();
var tcs = new TaskCompletionSource<LoginResult>();
cancellationToken.Register(() => tcs.TrySetCanceled());
purchases.Identify(appUserId, (purchaserInfo, error) =>
purchases.LogIn(appUserId, (customerInfo, created, error) =>
{
if (error != null)
{
tcs.TrySetException(new PurchasesErrorException(error, false));
}
else
{
tcs.TrySetResult(purchaserInfo);
tcs.TrySetResult(new LoginResult(customerInfo, created));
}
});
return tcs.Task;
Expand All @@ -33,7 +32,7 @@ public static Task<RCOfferings> GetOfferingsAsync(this RCPurchases purchases,
{
var tcs = new TaskCompletionSource<RCOfferings>();
cancellationToken.Register(() => tcs.TrySetCanceled());
purchases.OfferingsWithCompletionBlock((RCOfferings offerings, NSError error) =>
purchases.GetOfferingsWithCompletion((RCOfferings offerings, NSError error) =>
{
if (error != null)
{
Expand All @@ -53,7 +52,7 @@ public static Task<PurchaseSuccessInfo> PurchasePackageAsync(this RCPurchases pu
var tcs = new TaskCompletionSource<PurchaseSuccessInfo>();
cancellationToken.Register(() => tcs.TrySetCanceled());
purchases.PurchasePackage(packageToPurchase,
(SKPaymentTransaction transaction, RCPurchaserInfo purchaserInfo, NSError error, bool userCancelled) =>
(RCStoreTransaction transaction, RCCustomerInfo customerInfo, NSError error, bool userCancelled) =>
{
if (error != null)
{
Expand All @@ -65,45 +64,45 @@ public static Task<PurchaseSuccessInfo> PurchasePackageAsync(this RCPurchases pu
}
else
{
tcs.TrySetResult(new PurchaseSuccessInfo(transaction, purchaserInfo));
tcs.TrySetResult(new PurchaseSuccessInfo(transaction, customerInfo));
}
});
return tcs.Task;
}

public static Task<RCPurchaserInfo> RestoreTransactionsAsync(this RCPurchases purchases,
public static Task<RCCustomerInfo> RestoreTransactionsAsync(this RCPurchases purchases,
CancellationToken cancellationToken = default)
{
var tcs = new TaskCompletionSource<RCPurchaserInfo>();
var tcs = new TaskCompletionSource<RCCustomerInfo>();
cancellationToken.Register(() => tcs.TrySetCanceled());
purchases.RestoreTransactionsWithCompletionBlock((RCPurchaserInfo purchaserInfo, NSError error) =>
purchases.RestorePurchasesWithCompletion((RCCustomerInfo customerInfo, NSError error) =>
{
if (error != null)
{
tcs.TrySetException(new PurchasesErrorException(error, false));
}
else
{
tcs.TrySetResult(purchaserInfo);
tcs.TrySetResult(customerInfo);
}
});
return tcs.Task;
}

public static Task<RCPurchaserInfo> GetPurchaserInfoAsync(this RCPurchases purchases,
public static Task<RCCustomerInfo> GetCustomerInfoAsync(this RCPurchases purchases,
CancellationToken cancellationToken = default)
{
var tcs = new TaskCompletionSource<RCPurchaserInfo>();
var tcs = new TaskCompletionSource<RCCustomerInfo>();
cancellationToken.Register(() => tcs.TrySetCanceled());
purchases.PurchaserInfoWithCompletionBlock((RCPurchaserInfo purchaserInfo, NSError error) =>
purchases.GetCustomerInfoWithCompletion((RCCustomerInfo customerInfo, NSError error) =>
{
if (error != null)
{
tcs.TrySetException(new PurchasesErrorException(error, false));
}
else
{
tcs.TrySetResult(purchaserInfo);
tcs.TrySetResult(customerInfo);
}
});
return tcs.Task;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,69 @@
<?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.10</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>
<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageId>Xamarin.RevenueCat.iOS.Extensions</PackageId>
<Description>Contains convenience methods and async extensions for Xamarin.RevenueCat.iOS</Description>
<Version>4.1.0.4</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="PurchasesErrorException.cs"/>
<Compile Include="RCPurchasesExtensions.cs"/>
<Compile Include="Properties\AssemblyInfo.cs"/>
<Compile Include="PurchaseSuccessInfo.cs"/>
<Compile Include="LoginResult.cs"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="6.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</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>
Loading

0 comments on commit 31b6018

Please sign in to comment.