Skip to content

Commit

Permalink
comment out PKPayLaterValidateAmount bits until Apple replies
Browse files Browse the repository at this point in the history
  • Loading branch information
tj_devel709 committed Oct 19, 2023
1 parent d167a8a commit 049c2de
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 85 deletions.
120 changes: 61 additions & 59 deletions src/PassKit/PKPayLaterView.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
#nullable enable
// Can be uncommented when this issue is resolved: # https://github.com/xamarin/xamarin-macios/issues/19271

#if IOS && !__MACCATALYST__
// #nullable enable

using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using ObjCRuntime;
using Foundation;
using PassKit;
// #if IOS && !__MACCATALYST__

#if !NET
using NativeHandle = System.IntPtr;
#endif
// using System;
// using System.Runtime.InteropServices;
// using System.Runtime.CompilerServices;
// using ObjCRuntime;
// using Foundation;
// using PassKit;

namespace PassKit {
// #if !NET
// using NativeHandle = System.IntPtr;
// #endif

public partial class PKPayLaterView {
// namespace PassKit {

#if !NET
delegate void PKPayLaterValidateAmountCompletionHandler (IntPtr block, byte eligible);
static PKPayLaterValidateAmountCompletionHandler static_ValidateAmount = TrampolineValidateAmount;
// public partial class PKPayLaterView {

[MonoPInvokeCallback (typeof (PKPayLaterValidateAmountCompletionHandler))]
#else
[UnmanagedCallersOnly]
#endif
static void TrampolineValidateAmount (IntPtr block, byte eligible)
{
var del = BlockLiteral.GetTarget<Action<bool>> (block);
if (del is not null) {
del (eligible != 0);
}
}
// #if !NET
// delegate void PKPayLaterValidateAmountCompletionHandler (IntPtr block, byte eligible);
// static PKPayLaterValidateAmountCompletionHandler static_ValidateAmount = TrampolineValidateAmount;

#if NET
[SupportedOSPlatform ("ios17.0")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos")]
[UnsupportedOSPlatform ("tvos")]
#endif
[BindingImpl (BindingImplOptions.Optimizable)]
public static void ValidateAmount (NSDecimalNumber amount, string currencyCode, Action<bool> callback)
{
if (callback is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback));
// [MonoPInvokeCallback (typeof (PKPayLaterValidateAmountCompletionHandler))]
// #else
// [UnmanagedCallersOnly]
// #endif
// static void TrampolineValidateAmount (IntPtr block, byte eligible)
// {
// var del = BlockLiteral.GetTarget<Action<bool>> (block);
// if (del is not null) {
// del (eligible != 0);
// }
// }

unsafe {
#if NET
delegate* unmanaged<IntPtr, byte, void> trampoline = &TrampolineValidateAmount;
using var block = new BlockLiteral (trampoline, callback, typeof (PKPayLaterView), nameof (TrampolineValidateAmount));
#else
using var block = new BlockLiteral ();
block.SetupBlockUnsafe (static_ValidateAmount, callback);
#endif
var nsCurrencyCodePtr = NSString.CreateNative (currencyCode);
try {
PKPayLaterValidateAmount (amount.Handle, nsCurrencyCodePtr, &block);
} finally {
NSString.ReleaseNative (nsCurrencyCodePtr);
}
}
}
// #if NET
// [SupportedOSPlatform ("ios17.0")]
// [UnsupportedOSPlatform ("maccatalyst")]
// [UnsupportedOSPlatform ("macos")]
// [UnsupportedOSPlatform ("tvos")]
// #endif
// [BindingImpl (BindingImplOptions.Optimizable)]
// public static void ValidateAmount (NSDecimalNumber amount, string currencyCode, Action<bool> callback)
// {
// if (callback is null)
// ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback));

[DllImport (Constants.PassKitLibrary)]
unsafe static extern void PKPayLaterValidateAmount (IntPtr /* NSDecimalNumber */ amount, IntPtr /* NSString */ currencyCode, BlockLiteral* callback);
}
}
// unsafe {
// #if NET
// delegate* unmanaged<IntPtr, byte, void> trampoline = &TrampolineValidateAmount;
// using var block = new BlockLiteral (trampoline, callback, typeof (PKPayLaterView), nameof (TrampolineValidateAmount));
// #else
// using var block = new BlockLiteral ();
// block.SetupBlockUnsafe (static_ValidateAmount, callback);
// #endif
// var nsCurrencyCodePtr = NSString.CreateNative (currencyCode);
// try {
// PKPayLaterValidateAmount (amount.Handle, nsCurrencyCodePtr, &block);
// } finally {
// NSString.ReleaseNative (nsCurrencyCodePtr);
// }
// }
// }

#endif
// [DllImport (Constants.PassKitLibrary)]
// unsafe static extern void PKPayLaterValidateAmount (IntPtr /* NSDecimalNumber */ amount, IntPtr /* NSString */ currencyCode, BlockLiteral* callback);
// }
// }

// #endif
51 changes: 25 additions & 26 deletions tests/monotouch-test/PassKit/PKPayLaterViewTest.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
#if __IOS__ && !__MACCATALYST__
// Can be uncommented when this issue is resolved: # https://github.com/xamarin/xamarin-macios/issues/19271

using System;
using Foundation;
using UIKit;
using PassKit;
using NUnit.Framework;
// #if __IOS__ && !__MACCATALYST__

namespace MonoTouchFixtures.PassKit {
// using System;
// using Foundation;
// using UIKit;
// using PassKit;
// using NUnit.Framework;

[TestFixture]
[Preserve (AllMembers = true)]
public class PKPayLaterViewTest {
// namespace MonoTouchFixtures.PassKit {

[Test]
public void ValidateAmountTest ()
{
TestRuntime.AssertXcodeVersion (15, 0);
// [TestFixture]
// [Preserve (AllMembers = true)]
// public class PKPayLaterViewTest {

// From testing with Xcode 15.0.0, all values give the value of false to the completion handler.
// Perhaps this will change in the future.
// Apple feedback was submitted here: https://feedbackassistant.apple.com/feedback/13268898
for (int i = 0; i < 1000; i++){
PKPayLaterView.ValidateAmount (new NSDecimalNumber (i), "USD", (eligible) => {
Assert.False (eligible);
});
}
}
}
}
// [Test]
// public void ValidateAmountTest ()
// {
// TestRuntime.AssertXcodeVersion (15, 0);

#endif
// for (int i = 0; i < 1000; i++){
// PKPayLaterView.ValidateAmount (new NSDecimalNumber (i), "USD", (eligible) => {
// Assert.False (eligible);
// });
// }
// }
// }
// }

// #endif
3 changes: 3 additions & 0 deletions tests/xtro-sharpie/api-annotations-dotnet/iOS-PassKit.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@

# needed to allow our WeakDelegate wrap
!extra-null-allowed! 'System.Void PassKit.PKPayLaterView::set_WeakDelegate(Foundation.NSObject)' has a extraneous [NullAllowed] on parameter #0

# https://github.com/xamarin/xamarin-macios/issues/19271
!missing-pinvoke! PKPayLaterValidateAmount is not bound
3 changes: 3 additions & 0 deletions tests/xtro-sharpie/iOS-PassKit.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@

# needed to allow our WeakDelegate wrap
!extra-null-allowed! 'System.Void PassKit.PKPayLaterView::set_WeakDelegate(Foundation.NSObject)' has a extraneous [NullAllowed] on parameter #0

# https://github.com/xamarin/xamarin-macios/issues/19271
!missing-pinvoke! PKPayLaterValidateAmount is not bound

0 comments on commit 049c2de

Please sign in to comment.