2012-12-07 32 views

回答

0

是的,您可以使用FTP URL來加載圖像。

+0

感謝您的答覆,但我們需要爲該FTP設置憑證,您可以發佈一些代碼來執行此操作 – Ravi

+0

設置圖像文件的公共讀取權限,以便程序無需憑證即可訪問圖像。或者請嘗試ftp://用戶名:[email protected]/testimage.png –

1

看看蘋果的simple FTP example

一旦你可以訪問FTP服務器:

NSURL *theUrl = [NSURL URLWithString:@"ftp://userid:[email protected]/image.png"]; 
UIImage *newImage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:url]]; 
UIImageView *newImageView = [UIImageView imageViewWithImage:newImage]; 

請記住,這個過程需要時間,所以做一個後臺線程工作,以確保應用程序的響應能力。

+0

'imageWithContentsOfUrl'不存在。也許你的意思是:'UIImage * image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:url]];'? –

+1

當然可以,謝謝你的評論 – Stavash

+0

但是如果有這樣的方法,它會派上用場嗎? :) – Stavash

1

有一個很酷的庫叫SDWebImage。它會異步下載圖像,以便您的應用保持響應。它爲UIImageView添加了一個類別,因此您只需將URL傳遞給ImageView,一切都將自動完成。它也適用於ftp://的網址。

像這樣的東西應該工作:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f,0.0f,50.0f,50.0f)]; 

[imageView setImageWithURL:[NSURL URLWithString:@"ftp://example.com/path/image.jpeg"] 
       placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 

您還可以指定顯示,只要圖像不下載的佔位符。

相關問題