我正在尝试在我的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文件中出现错误意外的符号代理
[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创建的文件中添加委托?
答案 0 :(得分:1)
尽量不要在绑定代码中使用delegate
作为参数名称,因为它是C#中的保留字(并且生成器无法与保留字一起使用)。