iOS7編程Cookbook中例15.8中一個小問題

來源:互聯網
上載者:User

iOS7編程Cookbook中例15.8中一個小問題

該書的15.8例子標題為Editing Videos on an iOS Device,代碼的功能為建立一個UIImagePickerController視圖讓使用者從照片庫選擇一個視頻檔案,然後在UIVideoEditorController視圖中編輯該視頻,最後得到編輯後視頻檔案的路徑.

很好很簡單,但是在實際運行代碼中發現當UIImagePickerController返回後,在imagePickerController:(UIImagePickerController )picker didFinishPickingMediaWithInfo:(NSDictionary

NSString *mediaType = info[UIImagePickerControllerMediaType];    if ([mediaType isEqualToString:(__bridge NSString*)kUTTypeMovie]) {        _videoURLToEdit = info[UIImagePickerControllerMediaURL];    }

即執行後的_videoURLToEdit總為nil,即使前面的資源類型是正確的:為kUTTypeMovie類型.

網上搜了一下,發現很多人說在iOS9裡面都是這樣,包括Stack OF裡面也是如此.但不怎麼相信此說法…

後來到Apple SDK中尋找info字典的解釋:

info
A dictionary containing the original image and the edited image, if an image was picked; or a filesystem URL for the movie, if a movie was picked. The dictionary also contains any relevant editing information. The keys for this dictionary are listed in Editing Information Keys.

可以看到其所有key的解釋:

NSString *const UIImagePickerControllerMediaType;NSString *const UIImagePickerControllerOriginalImage;NSString *const UIImagePickerControllerEditedImage;NSString *const UIImagePickerControllerCropRect;NSString *const UIImagePickerControllerMediaURL;NSString *const UIImagePickerControllerReferenceURL;NSString *const UIImagePickerControllerMediaMetadata;NSString *const UIImagePickerControllerLivePhoto;

注意看其中包含一個UIImagePickerControllerReferenceURL枚舉,其說明稱該key的值為原始資源的URL.而UIImagePickerControllerMediaURL裡的值是當原始資源被修改後的URL.

我們前面總是返回nil,是因為我們沒有修改原始資源,所以總為空白值.

我們簡單的將代碼修改如下即可:

if ([mediaType isEqualToString:(__bridge NSString*)kUTTypeMovie]) {        _videoURLToEdit = info[UIImagePickerControllerMediaURL];        if (!_videoURLToEdit) {            _videoURLToEdit = info[UIImagePickerControllerReferenceURL];        }    }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.