我正在尝试链接内部使用AFNetworking
的原生iOS框架,我最初将其构建为原型,以便将我公司的部分ObjC IP移植到Xamarin以及未来
我开始创建一个简单的类,使用AFNetworking将小猫加载到UIImageView
中标题文件:
#import <UIKit/UIKit.h>
@interface FWSImageRepo : NSObject
+(UIImageView *)imageViewFromURLString:(NSString *)urlString;
@end
实施
@implementation FWSImageRepo
+(UIImageView *)imageViewFromURLString:(NSString *)urlString{
UIImageView *imageView = [[UIImageView alloc] init];
NSURL *imageUrl= [NSURL URLWithString:@"http://www.pets4homes.co.uk/images/articles/1334/large/6-health-issues-to-watch-for-in-young-kittens-52f62cff5cabb.jpg"];
if(imageUrl != nil) {
[imageView setImageWithURL:imageUrl];
}
return imageView;
}
@end
我创建了一个框架编译器目标,并将框架复制到Xamarin iOS项目中。我使用Objective Sharpie生成下面的绑定
// @interface FWSImageRepo : NSObject
[BaseType(typeof(NSObject))]
interface FWSImageRepo
{
// +(UIImageView *)imageViewFromURLString:(NSString *)urlString;
[Static]
[Export("imageViewFromURLString:")]
UIImageView ImageViewFromURLString(string urlString);
}
所有这些都按照binding project
中的指示链接,框架作为本机引用链接,绑定项目由单页Xamarin iOS应用程序引用。
现在仅仅初始化类var fwrepo = new FWSImageRepo();
向我表明框架根本不受项目的欢迎。即使我没有链接绑定项目中的框架
Could not create an native instance of the type 'FWSImageRepo': the native class hasn't been loaded. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.
有什么理由检查发生了什么事吗?我已经尝试了所有的东西并且在线搜索我的搜索。在我搜索的任何地方都没有这个要求的例子,几乎没有任何方向。我尝试过其他人面临同样问题的解决方案。我如何寻找出错的地方?
以下是我创建的项目https://drive.google.com/open?id=0B2f9RlRxZKoZcElIRkpLZnF6WVU
的链接答案 0 :(得分:2)
这并没有完全解决问题,但是由于@chris让我意识到这是一个没有加载类的问题,解决方案实际上是在修改iOS构建设置以匹配以下内容选择
我仍然只能静态访问该方法,如下所示:
// @interface FWSImageRepo : NSObject
[BaseType(typeof(NSObject))]
public interface FWSImageRepo
{
// +(UIImageView *)imageViewFromURLString:(NSString *)urlString;
[Static]
[Export("imageViewFromURLString:")]
UIImageView ImageViewFromURLString(string urlString);
}
并像这样访问
var imageview = FWSImageRepo.ImageViewFromURLString("");
知道为什么我不能将它用作实例(我删除了[Static]属性?
答案 1 :(得分:0)
无法创建“FWSImageRepo”类型的本机实例:尚未加载本机类。通过将ObjCRuntime.Class.ThrowOnInitFailure设置为false可以忽略此条件。
这表明尚未加载有问题的本机库。我会逐步完成文档:
https://developer.xamarin.com/guides/ios/advanced_topics/native_interop/
确定项目设置未在本机库中加载的位置。