我已閱讀Xamarin的文檔。如何將Objective-C靜態庫綁定到Xamarin.iOS?
這是我的測試類在Objective-C:
#import "XamarinBundleLib.h"
@implementation XamarinBundleLib
+(NSString *)testBinding{
return @"Hello Binding";
}
@end
這很容易,只有一個方法。
這是我的C#類:
namespace ResloveName
{
[BaseType (typeof (NSObject))]
public partial interface IXamarinBundleLib {
[Static,Export ("testBinding")]
NSString TestBinding {get;}
}
}
然後,這是我的AppDelegate代碼:
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
// Override point for customization after application launch.
// If not required for your application you can safely delete this method
string testStr = ResloveName.IXamarinBundleLib.TestBinding.ToString();
System.Console.WriteLine ("testStr="+testStr);
return true;
}
的TestBinding屬性爲空。 我一定在某個地方出了問題,所以我該如何解決?
你有沒有嘗試客觀Sharpie? https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-sharpie/ – iamIcarus
嘗試使用'string'綁定而不是'NSString'。如果這不起作用,出於某種原因,本地庫很可能沒有鏈接到可執行文件中(構建日誌會顯示這一點)。 –
我嘗試使用字符串而不是NSString,但這不正確。現在我想也許我的本地庫有些問題,我會檢查它。感謝您的建議。 –