2016-07-25 63 views
1

我試圖鏈接內部使用AFNetworking的本機iOS框架,我最初將其構建爲原型,將我公司的部分ObjC IP移植到可與Xamarin鏈接在將來。無法創建「FWSImageRepo」類型的本地實例。本地類尚未加載

我開始通過使加載使用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項目中。我用記號筆目的生成以下

// @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

無法創建類型「FWSImageRepo」的原生性實例項目鏈接:原生類尚未加載。通過將ObjCRuntime.Class.ThrowOnInitFailure設置爲false,可以忽略此情況。

這表明相關的本地庫尚未加載。我會通過文檔走:

https://developer.xamarin.com/guides/ios/advanced_topics/native_interop/

,以確定您的項目設置沒有在本地庫加載。

+0

是的,這聽起來對我來說也是如此,但我無法確定問題出在哪裏。感謝您的鏈接。 –

1

這並不完全解決問題,但由於@克里斯使我意識到,這是一個問題與不加載類,解決方案實際上是在修改了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(""); 

任何想法,爲什麼我不能使用它作爲一個實例(我刪除了[靜態]屬性?