简体   繁体   English

如何使用从绑定库到Xamarin iOS项目的方法

[英]how to use a method from binding library into Xamarin iOS project

I want to bind my iOS (Objective C) static library into XamariniOS so as per your documentation I have created a binding library project in xamarin studio and bind my ".a" file into binding project. 我想将我的iOS(目标C)静态库绑定到XamariniOS中,因此根据您的文档,我在xamarin Studio中创建了一个绑定库项目并将“ .a”文件绑定到绑定项目中。 I have also created .dll file and ApiDefination file using Objective Sharpie.I have created an xamarin iOS SingleView Application project and imported the library project and also add reference to the project.Now I want to call a method "void SetupWithId (int Id, string Key) " from my library in when the app goes Active in AppDelegate.cs so it should be call in OnActivated function and other method "void FetchUserDetails (string mobile)" inside ViewDidLoad. 我还使用Objective Sharpie创建了.dll文件和ApiDefination文件。我创建了xamarin iOS SingleView应用程序项目,并导入了库项目,还添加了对该项目的引用。现在,我要调用方法“ void SetupWithId(int Id,当应用程序在AppDelegate.cs中处于活动状态时从我的库中获取,因此应该在ViewDidLoad中的OnActivated函数和其他方法“ void FetchUserDetails(字符串移动)”中调用它。 My ApiDefination code is as follows: 我的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);
}  

Note: I have also imported namespace "MyLibrarySDK" inside AppDeligate.cs and created an object for my library also my AppDeligate.cs File is as follows: 注意:我还已经在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)
        {
        }
    }
}

till the above code there is no error in my project now I want to execute the above mentioned method. 直到上面的代码在我的项目中没有错误,现在我要执行上述方法。 How can I do this Please help me to do it. 我该怎么做请帮助我。

Thanks for the same. 谢谢你。

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

As per Gusman comment the above is worked for me. 根据古斯曼的评论,以上对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM