iOS開發之網路程式設計 獲取檔案的MIMEType

2021-09-08 17:49:44 字數 1200 閱讀 6546

前言:有時候我們需要獲取檔案的mimetype的資訊,下面就介紹關於獲取mimetype的方法。

2、用**獲取檔案的mimetype資訊:

1

#import

"getmimetype.h"2

3#import45

@implementation

getmimetype67

#pragma mark - 類方法

8 + (nsstring*)getmimetypeurlrequestatfilepath:(nsstring*)path

1112 + (nsstring *)getmimetypewithcapiatfilepath:(nsstring *)path

15#pragma mark - 物件方法

16//

向該檔案傳送請求,根據請求頭拿到該檔案的mimetype

17 -(nsstring *)getmimetypeurlrequestatpath:(nsstring*)path

1832

33//

呼叫c語言的api來獲得檔案的mimetype ,只能獲取本地檔案哦,無法獲取網路請求來的檔案

34 -(nsstring *)getmimetypewithcapiatfilepath:(nsstring *)path

3539

40 cfstringref uti =uttypecreatepreferredidentifierfortag(kuttagclassfilenameextension, (__bridge cfstringref)[path pathextension], null);

41 cfstringref mimetype =uttypecopypreferredtagwithclass (uti, kuttagclassmimetype);

42cfrelease(uti);

43if (!mimetype)

46return (__bridge nsstring *)(mimetype)47;

48}4950

@end

執行:

iOS開發之網路程式設計 獲取檔案的MIMEType

前言 有時候我們需要獲取檔案的mimetype的資訊,下面就介紹關於獲取mimetype的方法。2 用 獲取檔案的mimetype資訊 import getmimetype.h import implementation getmimetype pragma mark 類方法 nsstring ge...

iOS開發之網路程式設計 常用網路協議

看了上面那句不明所以得話,好像並沒有什麼luan用。在第一章有提過協議這個概念,就像咱們工作的時候,籤的協議,生活中的保單協議,都需要雙方同意簽字,才能生效。基於網路的應用就決定了資料鏈上不僅僅只有客戶端 應用 這一環,還需要有伺服器 資料來源 這一環。那我們的應用在與伺服器互動的時候,伺服器憑什麼...

iOS開發 獲取網路狀態

之前用的根據狀態列獲取的,ios 13貌似不行了。import typedef enum network type inte ce basetooles nsobject network type sdkgetnetworktypefromstatusbar 獲取當前網路型別 通過statusbar...