我正在尝试让绑定项目工作。但是我遇到了一个错误,它不喜欢我将委托作为参数传递给另一个委托。
我收到的错误是这样的;
"Attempting to JIT compile method '(wrapper runtime-invoke)
:BackgroundFetchResultHandler(object,UIBackgroundFetchResult)' while running
with --aot-only.
有关详细信息,请参阅http://docs.xamarin.com/ios/about/limitations。\n "
所以发生的事情是我正在使用 PushySDK 并创建了一个绑定库项目。除了 BackgroundFetchResultHandler 委托之外,绑定项目中的所有内容都有效。如果我尝试对 BackgroundFetchResultHandler 使用操作或 Func 而不是委托,则绑定库将无法编译。
我的 apiDefinitions.cs 文件是这样的;
using System;
using Foundation;
using UIKit;
namespace PushySDK
{
public delegate void BackgroundFetchResultHandler(UIBackgroundFetchResult result);
public delegate void NotificationHandler(NSDictionary info, BackgroundFetchResultHandler action);
// @interface Pushy : NSObject
[BaseType(typeof(NSObject), Name = "_TtC8PushySDK5Pushy")]
[DisableDefaultCtor]
interface Pushy
{
// -(instancetype _Nonnull)init:(UIResponder * _Nonnull)appDelegate application:(UIApplication * _Nonnull)application __attribute__((objc_designated_initializer));
[Export("init:application:")]
[DesignatedInitializer]
IntPtr Constructor(UIResponder appDelegate, UIApplication application);
// -(void)setNotificationHandler:(void (^ _Nonnull)(NSDictionary * _Nonnull, void (^ _Nonnull)(UIBackgroundFetchResult)))notificationHandler;
[Export("setNotificationHandler:")]
void SetNotificationHandler(NotificationHandler notificationHandler);
// -(void)register:(void (^ _Nonnull)(NSError * _Nullable, NSString * _Nonnull))registrationHandler;
[Export("register:")]
void Register(Action<NSError, NSString> registrationHandler);
}
}
我试图使用操作而不是委托,但我得到了同样的错误。如果我将 NotificationHandler Delegate 更改为;
public delegate void NotificationHandler(NSDictionary info, int action);
一切都很好,除了我不能调用回调,因为它是一个 int。但是我的推送通知工作正常,一切都很好。
所以我只是想找到一种方法来调用这个回调而不会崩溃。似乎当 Xamarin 生成绑定代码时,它在决定第二个委托应该是什么类型时遇到了很多麻烦。
如果我这样使用 NotificationNHandler;
public delegate void NotificationHandler(NSDictionary info, Action<UIBackgroundFetchResult> action);
绑定库无法编译,我收到有关无效字符“Action`1”的错误
有没有人能想到让这个工作。提前致谢!