Reputation: 874
I am trying to use Crashlytics iOS library in my MonoTouch app. I have created a MonoTouch Binding project and created ApiDefinition.cs file using Object Sharpie tool. Below is my 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);
}
}
When i compile project i am getting error at NSObject delegate. So i have added @, recommendation from here
[Static, Export ("startWithAPIKey:delegate:")]
Crashlytics StartWithAPIKey (string apiKey, NSObject @delegate);
[Static, Export ("startWithAPIKey:delegate:afterDelay:")]
Crashlytics StartWithAPIKey (string apiKey, NSObject @delegate, double delay);
Now i compile again, i get error at Crashlytics.g.cs file 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;
}
how to add delegate in the file created using Object Sharpie?
Upvotes: 0
Views: 516
Reputation: 19345
Try not using delegate
as a parameter name in your binding code, since it's a reserved word in C# (and the generator doesn't work properly with reserved words).
Upvotes: 1