【问题标题】:Using Crashlytics in MonoTouch在 MonoTouch 中使用 Crashlytics
【发布时间】:2014-02-12 22:23:05
【问题描述】:

我正在尝试在我的 MonoTouch 应用程序中使用 Crashlytics iOS 库。我创建了一个 MonoTouch Binding 项目并使用 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 委托处遇到错误。所以我加了@,来自here的推荐

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

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

现在我再次编译,我在 Crashlytics.g.cs 文件 Unexpected Symbol delegate 处收到错误

     [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;
    }

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

【问题讨论】:

    标签: binding xamarin.ios


    【解决方案1】:

    尽量不要在绑定代码中使用 delegate 作为参数名称,因为它是 C# 中的保留字(并且生成器不能与保留字一起正常工作)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多