我想将我的iOS(Objective C)静态库绑定到XamariniOS中,因此根据您的文档,我在xamarin studio中创建了一个绑定库项目并绑定了我的" .a"文件到绑定项目。我还使用Objective Sharpie创建了.dll文件和ApiDefination文件。我创建了一个xamarin iOS SingleView应用程序项目并导入了库项目并添加了对项目的引用。现在我想调用一个方法" void SetupWithId( int Id,string Key)"来自我的库,当应用程序在AppDelegate.cs中变为活动时,应该在OnActivated函数和其他方法中调用" void FetchUserDetails(string mobile)"在ViewDidLoad中。我的ApiDefination代码如下:
using System;
using UIKit;
using Foundation;
using ObjCRuntime;
using CoreGraphics;
namespace MyLibrarySDK
{
// @interface IMyLibrary : NSObject
[BaseType (typeof(NSObject))]
interface MyLibrary
{
// @property (nonatomic, strong) NSTimer * setupCompleteTimer;
[Export ("setupCompleteTimer", ArgumentSemantic.Strong)]
NSTimer SetupCompleteTimer { get; set; }
// +(void)setupWithId:(int)Id Key:(NSString *)Key;
[Static]
[Export ("setupWithId:Key:")]
void SetupWithId (int Id, string Key);
// +(void)fetchSettings;
[Static]
[Export ("fetchSettings")]
void FetchSettings ();
// +(void)fetchUserDetails:(NSString *)mobile;
[Static]
[Export ("fetchUserDetails:")]
void FetchUserDetails (string mobile);
}
注意:我还导入了名称空间" MyLibrarySDK"在AppDeligate.cs中为我的库创建了一个对象,我的AppDeligate.cs文件如下:
using Foundation;
using UIKit;
using MyLibrarySDK;
namespace TestiOSProject
{
[Register ("AppDelegate")]
public class AppDelegate : UIApplicationDelegate
{
// class-level declarations
public MyLibrary mylib;
public override UIWindow Window {
get;
set;
}
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
return true;
}
public override void OnResignActivation (UIApplication application)
{
}
public override void DidEnterBackground (UIApplication application)
{
}
public override void WillEnterForeground (UIApplication application)
{
}
public override void OnActivated (UIApplication application)
{
mylib = new MyLibrary();
}
public override void WillTerminate (UIApplication application)
{
}
}
}
直到上面的代码我的项目中没有错误现在我想执行上面提到的方法。我该怎么做请帮我做。
谢谢你。
答案 0 :(得分:0)
public override void OnActivated (UIApplication application)
{
mylib = new MyLibrary();
mylib.SetupWithId(parameter1IntValue, "parameter2StringValue");
}
根据古斯曼的评论,上述内容对我有用。