我有一个相当大的iOS框架需要绑定。这一框架取决于另外两个框架。
我创建了绑定项目,成功地生成了ApiDefinitions.cs文件和StructsAndEnums.cs。到目前一切尚好。
现在,当我尝试在Debug模式下构建它时,我会看到关于临时文件中语法问题的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/Miiite/367e17335431e932acdc92c65b504bd4
EDIT2:下面是作为日志输出https://gist.github.com/Miiite/e272622df2e853d53f1add4c8eb4eabf生成的sharpie
发布于 2018-03-05 19:52:58
我相信问题就在这里:void PresentCheckoutForSubmittingTransactionCompletionHandler(Action<OPPTransaction, NSError> completionHandler, [NullAllowed] Action<NSString, Action<NSString>> paymentBrandSelectedHandler, [NullAllowed] Action cancelHandler);
我认为引起了问题,生成器可能不支持这一点,所以您可能需要找到一种不同的绑定方法。
发布于 2018-03-18 04:35:58
这个有问题的方法肯定是可以绑定的,如果您需要的话,这里是如何绑定的(为了简洁起见,我省略了其他类成员):
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,您需要将其分解为两个委托,并使用BlockCallback属性指示生成器将参数封送为ObjC块,然后只使用父委托作为PresentCheckoutForSubmittingTransactionCompletionHandler方法中paymentBrandSelectedHandler参数的类型。
希望这能帮你彻底解除障碍。这就是说,我们应该报告一个更好的错误,我将与团队讨论,看看。
干杯!
https://stackoverflow.com/questions/49054254
复制相似问题