3

我有一个相当庞大的 iOS 框架要绑定。这个框架依赖于另外两个。

我创建了绑定项目,成功生成了ApiDefinitions.cs文件和StructsAndEnums.cs。到目前为止,一切都很好。

现在,当我尝试在调试模式下构建它时,我收到大约 30 多个关于临时文件中的语法问题的错误。

这些错误仅发生在 Trampolines.g.cs 和 SupportDelegates.g.cs 文件中。两者中最糟糕的是 SupportDelegates.g.cs 文件,它看起来像这样:

   //
// Auto-generated from generator.cs, do not edit
//
// We keep references to objects, so warning 414 is expected

#pragma warning disable 414

using System;
using System.Drawing;
using System.Diagnostics;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using UIKit;
using GLKit;
using Metal;
using MapKit;
using Photos;
using ModelIO;
using SceneKit;
using Contacts;
using Security;
using Messages;
using AudioUnit;
using CoreVideo;
using CoreMedia;
using QuickLook;
using CoreImage;
using SpriteKit;
using Foundation;
using CoreMotion;
using ObjCRuntime;
using AddressBook;
using MediaPlayer;
using GameplayKit;
using CoreGraphics;
using CoreLocation;
using AVFoundation;
using NewsstandKit;
using FileProvider;
using CoreAnimation;
using CoreFoundation;

namespace System.Action`1[[Foundation.NSString, Xamarin.iOS, Version=0.0.0 {
    public delegate void 0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]] (NSString obj);
}

Trampolines.g.cs 文件几乎完全生成,但在生成的 C# 代码中间出现了同样的问题:

static internal class SDActionArity2V1 {
            static internal readonly DActionArity2V1 Handler = Invoke;

            [MonoPInvokeCallback (typeof (DActionArity2V1))]
            static unsafe void Invoke (IntPtr block, IntPtr arg1, IntPtr arg2) {
                var descriptor = (BlockLiteral *) block;
                var del = (global::System.Action<NSString, global::System.Action<NSString>>) (descriptor->Target);
                if (del != null)
                    del ( Runtime.GetNSObject<NSString> (arg1), (System.Action`1[Foundation.NSString]) Marshal.GetDelegateForFunctionPointer (arg2, typeof (System.Action`1[Foundation.NSString])));
            }
        }

其他一些绑定项目正在生成相同类型的文件,并且一切似乎都工作正常,所以我实际上正在努力寻找其根本原因。

有任何想法吗 ?

编辑:这里提供更多信息是生成的接口定义 https://gist.github.com/Miiie/367e17335431e932acdc92c65b504bd4

EDIT2:这是作为日志输出生成的Sharpie https://gist.github.com/Miiiite/e272622df2e853d53f1add4c8eb4eabf

4

2 回答 2

5

我相信问题在这里: void PresentCheckoutForSubmittingTransactionCompletionHandler(Action<OPPTransaction, NSError> completionHandler, [NullAllowed] Action<NSString, Action<NSString>> paymentBrandSelectedHandler, [NullAllowed] Action cancelHandler);

我认为 Action 中的 Action 导致了问题,生成器可能不支持这一点,因此您可能需要找到一种不同的绑定方式。

于 2018-03-05T19:52:58.843 回答
3

这个有问题的方法绝对可以绑定,如果你需要它是怎么做的(为了简洁,我省略了其余的类成员):

delegate void OPPPaymentBrandSelectedHandler (string paymentBrand, [BlockCallback] OPPPaymentCompletionHandler completionHandler);
delegate void OPPPaymentCompletionHandler ([NullAllowed] string checkoutId);

[BaseType (typeof (NSObject))]
interface OPPCheckoutProvider {

    // -(void)presentCheckoutForSubmittingTransactionCompletionHandler:(void (^ _Nonnull)(OPPTransaction * _Nullable, NSError * _Nullable))completionHandler
    // paymentBrandSelectedHandler:(void (^ _Nullable)(NSString * _Nonnull, void (^ _Nonnull)(NSString * _Nullable)))paymentBrandSelectedHandler 
    // cancelHandler:(void (^ _Nullable)(void))cancelHandler;
    [Export("presentCheckoutForSubmittingTransactionCompletionHandler:paymentBrandSelectedHandler:cancelHandler:")]
    void PresentCheckoutForSubmittingTransactionCompletionHandler(Action<OPPTransaction, NSError> completionHandler, [NullAllowed] OPPPaymentBrandSelectedHandler paymentBrandSelectedHandler, [NullAllowed] Action cancelHandler);
}

诀窍是不要使用嵌套Action的 s,而是需要将其分成两个委托并使用BlockCallback属性来指示生成器将参数编组为 ObjC 块,然后只需使用父委托作为paymentBrandSelectedHandler内部参数的类型PresentCheckoutForSubmittingTransactionCompletionHandler方法。

希望这有助于让您完全畅通无阻。也就是说,我们应该报告一个更好的错误,我将与团队讨论并看看。

干杯!

于 2018-03-18T04:35:58.620 回答