2014年12月19日 星期五

Build VLC with many 404 file not found

今天下載了 vls for iOS, 隨手  build 了一下,一直被中斷,因為 vlc server  上的檔案搬家了:


用網頁去連,顯示 404 File not found.

在google 了一堆檔案後,把tar 檔放進目錄裡:
ImportedSources ▸ VLCKit ▸ MobileVLCKit ▸ ImportedSources ▸ vlc ▸ contrib ▸ tarballs


重新 build, 又有新的 error message.

ragel 問題的解法:
http://ios-imaxlive.blogspot.tw/2014/12/how-to-install-ragel-on-mac.html



從官方取得新版的code, 並解決 lost file, 再安裝完 ragel 在 14:45, 開始重  build ,build 了


檔案:Screen Shot 2014-12-19 at 3.50.42 PM
說明:已build 1小時又5分鐘,還沒 build 完。



檔案:Screen Shot 2014-12-19 at 3.52.05 PM
說明:歐耶,build 了1小時又7分鐘. 感動,新版 VLC build 出來了。



2014年12月18日 星期四

how to install Ragel on Mac

為了build VLC,居然要學習如何安裝 ragel.

Step 1. 下載 tar 檔:
http://www.colm.net/open-source/ragel/

http://www.colm.net/files/ragel/ragel-6.9.tar.gz

Step 2:
tar xzf ragel-6.9.tar.gz
$ cd ragel-6.9
$ ./configure
$ make
$ sudo make install


Pull is not possible because you have unmerged files.g

之前修改了 VLC 的 source code 裡的 (ios ▸ ImportedSources ▸ VLCKit ▸ MobileVLCKit ▸ ImportedSources ▸ vlc ▸ securetransport.c), 今天又有需求要改,所以想 git pull 下來新的 code 來 build, 但 git stash , 再 git pull 後,show error message:
Pull is not possible because you have unmerged files.

解法:
git fetch origin
git reset --hard origin/master

from:
最後還是怪怪的,無法 build 起來,所以看了一下 /ImportedSources/VLCKit/buildMobileVLCKit.sh 裡的內容,有寫:

mkdir -p MobileVLCKit/ImportedSources

spushd MobileVLCKit/ImportedSources

if [ "$NONETWORK" != "yes" ]; then
if ! [ -e vlc ]; then
git clone git://git.videolan.org/vlc.git vlc
info "Applying patches to vlc.git"
cd vlc
git checkout -B localBranch ${TESTEDHASH}
git branch --set-upstream-to=origin/master localBranch
git am ../../patches/*.patch
if [ $? -ne 0 ]; then
git am --abort
info "Applying the patches failed, aborting git-am"
exit 1
fi
cd ..
else
cd vlc
git reset --hard ${TESTEDHASH}
git am ../../patches/*.patch
cd ..
fi

fi


所以,我直接把 MobileVLCKit/ 砍掉後,再執行 buildMobileVLCKit.sh 就可以拿到最新版的本了。


2014年12月12日 星期五

iOS8 App Extension - Document Provider

開始研究什麼是 Document Provider, 先到 Apple 的官網來進行 study:

Document Provider
https://developer.apple.com/library/mac/documentation/General/Conceptual/ExtensibilityPG/FileProvider.html#//apple_ref/doc/uid/TP40014214-CH18-SW5

In iOS, any app that remotely stores commonly used document formats should consider creating a Document Provider extension. This extension (sometimes shortened here to document provider) allows other apps to access the documents managed by your app. Additionally, apps that are strongly associated with a specific document type may benefit from creating a document provider for their documents. Here, the document provider act as a local repository for a particular type of document, letting the user gather all those documents into one place.
Documents managed by your Document Provider extension can be accessed by any app using a document picker view controller. This combination gives users a lot of flexibility when it comes to managing and sharing their documents.
所以, Document Provider 就是一個讓別人挑選我們檔案的一個介面.


如何 Creating the File Provider Extension:
https://developer.apple.com/library/mac/documentation/General/Conceptual/ExtensibilityPG/FileProvider.html#//apple_ref/doc/uid/TP40014214-CH18-SW8


由於是獨立的 App ID, 所以有需要設定 Shared Container:
https://developer.apple.com/library/mac/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW19


接下來就是, 要實作 NSFileProviderExtension, Apple 說這2個 method 不要去動他:
  • writePlaceholderAtURL:withMetadata:error:
  • placeholderURLForURL:

建議我們實作:
  • providerIdentifier
  • documentStorageURL
  • persistentIdentifierForItemAtURL:
  • URLForItemWithPersistentIdentifier:

這4個是一定要實作:
  • providePlaceholderAtURL:completionHandler:
  • startProvidingItemAtURL:completionHandler:
  • itemChangedAtURL:
  • stopProvidingItemAtURL:
中文翻譯如下:
http://www.cocoachina.com/ios/20141007/9835.html


在實作的時候, 有些元件無法使用在 App Extension 裡, 例如 UIAlertView 要改用 UIAlertController. 這個 UIAlertController 真的很神奇又好用


最佳(比Apple官方相比)&最簡單的範例下載:
https://github.com/D2B-Solution

複雜功能強的 seafile:

寫了2個星期,第1個"完整功能"的版本終於出來,接下來開始調UI。

dismissGrantingAccessToURL of UIDocumentPickerExtensionViewController is not working

在確定要檔案有放到指定的路徑後,執行
dismissGrantingAccessToURL,

發現App Extension視窗沒被收起來。

這應該是 Apple 的 bug, 我試了 reboot device, clean project, 都無效。

但是,2014-12-12 ,reboot 完系統彈出對話框,問我要不要從 iOS 8.1.1 upgrade to iOS 8.1.2 我升完後,一切就都正常了,視窗收的起來。

Delete app on device, 再 install 進去也一樣無效,app extension window 不會被收起來。收不起來的原因可能有很多,例如:

  • 檔案很大要處理很久。
  • 傳進去的 NSURL 有錯,造成exception, 所畫面停住。


結論是,下面別人附的建議方式,都無效,還是拿到正確的範例才能正確地傳回檔案給import 的 app, 還有關掉畫面上的 app extension.

相關討論:
http://stackoverflow.com/questions/26257718/dismissgrantingaccesstourl-of-uidocumentpickerextensionviewcontroller-is-not-wor


最佳(比Apple官方相比)&最簡單的範例下載:
https://github.com/D2B-Solution

NSInternalInconsistencyException - dismissed with a URL not contained in its documentStorageURL


dismissGrantingAccessToURL 的 URL 需要在 documentStorageURL 目錄下,不然會出錯:

*** Assertion failure in -[DocumentPickerViewController dismissGrantingAccessToURL:], /SourceCache/UIKit/UIKit-3318.16.21/UIDocumentPickerExtensionViewController.m:44
2014-12-13 00:56:30.936 Provider[2059:42072] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<DocumentPickerViewController: 0x16d864c0> dismissed with a URL (file:///var/mobile/Containers/Data/PluginKitPlugin/F7F9D086-A71F-4F54-9667-2F2914DD2028/Library/Caches/files/2014-08-28%2011_58_51-Chromium%20OS%20builds%20by%20Hexxeh.jpg) not contained in its documentStorageURL (file:///private/var/mobile/Containers/Shared/AppGroup/CFF8D9E2-2AB3-4F42-B8F6-84250A221E41/File%20Provider%20Storage/)'


最佳(比Apple官方相比)&最簡單的範例下載:
https://github.com/D2B-Solution

NSCocoaErrorDomain Code=516

在 copy file to shared container 時,第1次是OK, 沒有錯誤,第2次就掛掉,會有Error message, error code=516.



NSUnderlyingError=0x14dcfdd0 "The operation couldn’t be completed. File exists"} (/var/mobile/Containers/Data/PluginKitPlugin/F0463B01-1850-4A9B-8631-19A5DF8A2AC6/Library/Caches/files/Screenshot_2014-12-08-20-00-19.p(lldb)

原來是 File exists 造成,所以要先判斷,檔案是否存在,和屬性,但我很懶,決定直接先刪掉目的地的檔案。

原理:
https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html



相關文章:
http://stackoverflow.com/questions/25150579/sharing-bundled-assets-between-app-and-extension

If you want to share files between your iOS8 extension and your Containing app, you want to write files to a shared container or use the shared user defaults.
From Apple's iOS8 current documentation:
By default, your containing app and its extensions have no direct access to each other’s containers
You want to create an App Group, and add your containing app and its extensions to this group. 
in the app group name, input a constant like:
group.com.bundle.app.soething
This creates a shared container for your containing app and extension, which allows:
  • Share NSUserDefaults:
    [[NSUserDefaults alloc] initWithSuiteName:@"group.com.bundle.app.soething"];
  • Share a directory on the filesystem:
    NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.bundle.app.soething"];
EDIT this will print out all the path combinations we have:
// App group's path

NSURL  *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.test.app"];

NSLog(@"App group: %@", containerURL.path);



// Bundle path

NSLog (@"Bundle: %@", [[NSBundle mainBundle] bundlePath]);



// Good old Documents path

NSArray *Paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *path = [Paths objectAtIndex:0];

NSLog(@"Documents: %@ ", path);
I hope this helps you :)





Facebook 留言