Binding 在MonoTouch中使用Crashlytics

Binding 在MonoTouch中使用Crashlytics,binding,xamarin.ios,Binding,Xamarin.ios,我正在尝试在我的MonoTouch应用程序中使用Crashlytics iOS库。我已经创建了一个MonoTouch绑定项目,并使用Object Sharpie工具创建了ApiDefinition.cs文件。 下面是我的ApiDefinition.cs using System; using MonoTouch.ObjCRuntime; using MonoTouch.Foundation; using MonoTouch.UIKit; namespace Crashlytics { [B

我正在尝试在我的MonoTouch应用程序中使用Crashlytics iOS库。我已经创建了一个MonoTouch绑定项目,并使用Object Sharpie工具创建了ApiDefinition.cs文件。 下面是我的ApiDefinition.cs

using System;
using MonoTouch.ObjCRuntime;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

 namespace Crashlytics {

[BaseType (typeof (NSObject))]
public partial interface Crashlytics {

    [Export ("apiKey", ArgumentSemantic.Copy)]
    string ApiKey { get; }

    [Export ("version", ArgumentSemantic.Copy)]
    string Version { get; }

    [Export ("debugMode")]
    bool DebugMode { get; set; }

    [Export ("delegate", ArgumentSemantic.Assign)]
    NSObject Delegate { get; set; }

    [Static, Export ("startWithAPIKey:")]
    Crashlytics StartWithAPIKey (string apiKey);

    [Static, Export ("startWithAPIKey:afterDelay:")]
    Crashlytics StartWithAPIKey (string apiKey, double delay);

    [Static, Export ("startWithAPIKey:delegate:")]
    Crashlytics StartWithAPIKey (string apiKey, NSObject @delegate);

    [Static, Export ("startWithAPIKey:delegate:afterDelay:")]
    Crashlytics StartWithAPIKey (string apiKey, NSObject @delegate, double delay);


    [Static, Export ("sharedInstance")]
    Crashlytics SharedInstance { get; }

    [Export ("crash")]
    void Crash ();

    [Export ("userIdentifier")]
    string UserIdentifier { set; }

    [Export ("userName")]
    string UserName { set; }

    [Export ("userEmail")]
    string UserEmail { set; }

    [Export ("setObjectValue:forKey:")]
    void SetObjectValue (NSObject value, string key);

    [Export ("setIntValue:forKey:")]
    void SetIntValue (int value, string key);

    [Export ("setBoolValue:forKey:")]
    void SetBoolValue (bool value, string key);

    [Export ("setFloatValue:forKey:")]
    void SetFloatValue (float value, string key);
    /*
    [Static, Export ("setObjectValue:forKey:")]
    void SetObjectValue (NSObject value, string key);

    [Static, Export ("setIntValue:forKey:")]
    void SetIntValue (int value, string key);

    [Static, Export ("setBoolValue:forKey:")]
    void SetBoolValue (bool value, string key);

    [Static, Export ("setFloatValue:forKey:")]
    void SetFloatValue (float value, string key);
    */
}

[Model, BaseType (typeof (NSObject))]
public partial interface CLSCrashReport {

    [Export ("identifier")]
    string Identifier { get; }

    [Export ("customKeys")]
    NSDictionary CustomKeys { get; }

    [Export ("bundleVersion")]
    string BundleVersion { get; }

    [Export ("bundleShortVersionString")]
    string BundleShortVersionString { get; }

    [Export ("crashedOnDate")]
    NSDate CrashedOnDate { get; }

    [Export ("OSVersion")]
    string OSVersion { get; }

    [Export ("OSBuildVersion")]
    string OSBuildVersion { get; }
}

[BaseType(typeof(NSObject))]
[Model]
public partial interface CrashlyticsDelegate {

    [Export ("crashlytics:crashlyticsDidDetectCrashDuringPreviousExecution:")]
    void  CrashlyticsDidDetectCrashDuringPreviousExecution(Crashlytics crashlytics);

    [Export ("crashlytics:didDetectCrashDuringPreviousExecution:")]
    void DidDetectCrashDuringPreviousExecution (Crashlytics crashlytics, CLSCrashReport crash);
}
}
当我编译项目时,NSObject委托出现错误。所以我加了,来自

现在我再次编译,在Crashlytics.g.cs文件中出现错误

     [Export ("startWithAPIKey:delegate:")]
    [CompilerGenerated]
    public static Crashlytics StartWithAPIKey (string apiKey, NSObject delegate)
    {
        if (apiKey == null)
            throw new ArgumentNullException ("apiKey");
        if (delegate == null)
            throw new ArgumentNullException ("delegate");
        var nsapiKey = NSString.CreateNative (apiKey);

        Crashlytics ret;
        ret =  Runtime.GetNSObject<Crashlytics> (MonoTouch.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr (class_ptr, selStartWithAPIKeyDelegate_Handle, nsapiKey, delegate.Handle));
        NSString.ReleaseNative (nsapiKey);

        return ret;
    }
[导出(“StartWithApKey:delegate:”)]
[编译生成]
公共静态Crashlytics startwithapkey(字符串apiKey,NSObject委托)
{
if(apiKey==null)
抛出新ArgumentNullException(“apiKey”);
if(委托==null)
抛出新的异常(“委托”);
var nsapiKey=NSString.CreateNative(apiKey);
Crashlytics-ret;
ret=Runtime.GetNSObject(MonoTouch.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr_IntPtr(class_ptr,selstartwithapKeyDelegate_Handle,nsapkey,delegate.Handle));
NSString.ReleaseNative(nsapiKey);
返回ret;
}

如何在使用Object Sharpie创建的文件中添加委托?

请尝试在绑定代码中不要使用
delegate
作为参数名,因为它在C#中是一个保留字(并且生成器不能正确使用保留字)

     [Export ("startWithAPIKey:delegate:")]
    [CompilerGenerated]
    public static Crashlytics StartWithAPIKey (string apiKey, NSObject delegate)
    {
        if (apiKey == null)
            throw new ArgumentNullException ("apiKey");
        if (delegate == null)
            throw new ArgumentNullException ("delegate");
        var nsapiKey = NSString.CreateNative (apiKey);

        Crashlytics ret;
        ret =  Runtime.GetNSObject<Crashlytics> (MonoTouch.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr (class_ptr, selStartWithAPIKeyDelegate_Handle, nsapiKey, delegate.Handle));
        NSString.ReleaseNative (nsapiKey);

        return ret;
    }