2016-03-02 21 views
0

我想根據您的文檔將我的iOS(Objective C)靜態庫綁定到XamariniOS中我已經在xamarin studio中創建了綁定庫項目並綁定了我的「.a 「文件進入綁定項目。我也使用Objective Sharpie創建了.dll文件和ApiDefination文件。我創建了一個xamarin iOS單視圖應用程序項目,並導入了庫項目並添加了對項目的引用。現在我想調用一個方法「void SetupWithId(int Id,字符串鍵)「從我的庫中,當應用程序在AppDelegate.cs中處於活動狀態時,應該在ViewDidLoad中調用OnActivated函數和其他方法」void FetchUserDetails(string mobile)「。我ApiDefination代碼如下:如何使用將庫綁定到Xamarin iOS項目中的方法

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

mylib = new MyLibrary(); mylib.SetupWithId(Id,Key); – Gusman

+0

謝謝古斯曼它的工作。 –

回答

0
public override void OnActivated (UIApplication application) 
{ 
    mylib = new MyLibrary(); 
    mylib.SetupWithId(parameter1IntValue, "parameter2StringValue");  
} 

根據Gusman的評論,上述內容適用於我。

相關問題