【发布时间】:2016-03-02 09:54:03
【问题描述】:
我想将我的 iOS(Objective C)静态库绑定到 XamariniOS,以便根据您的文档,我在 xamarin studio 中创建了一个绑定库项目,并将我的“.a”文件绑定到绑定项目中。我还使用 Objective Sharpie 创建了 .dll 文件和 ApiDefination 文件。我创建了一个 xamarin iOS SingleView 应用程序项目并导入了库项目并添加了对项目的引用。现在我想调用一个方法“void SetupWithId (int Id, string Key)” 来自我的库,当应用程序在 AppDelegate.cs 中处于活动状态时,应该在 OnActivated 函数和 ViewDidLoad 中的其他方法“void FetchUserDetails (string mobile)”中调用它。我的 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);
}
注意:我还在 AppDeligate.cs 中导入了命名空间“MyLibrarySDK”,并为我的库创建了一个对象,我的 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)
{
}
}
}
直到上面的代码在我的项目中没有错误现在我想执行上面提到的方法。我该怎么做请帮我做。
谢谢你。
【问题讨论】:
-
mylib = new MyLibrary(); mylib.SetupWithId(Id, Key);
-
感谢古斯曼的工作。
标签: c# xamarin xamarin.ios