본문 바로가기
프로그래밍 놀이터/iOS

[iOS] 앱이 지원하는 File Type 등록하고 처리하기

by 돼지왕 왕돼지 2018. 2. 20.
반응형

[iOS] 앱이 지원하는 File Type 등록하고 처리하기


application:didFinishLaunchingWithOptions, application:willFinishLaunchingWithOptions, array, background, bundle id, CFBundleDocumentTypes, CFBundleTypeIconFiles, CFBundleTypeNames, dictionary, file type, file type 등록, Info.plist, IOS, Key, LSHandlerRank, LSItemContentTypes, LSItemContenTypes, openURL, property list, sourceApplication, UIApplicationLaunchOptionsAnnotationKey, UIApplicationLaunchOptionsSourceApplicationKey, UIApplicationLaunchOptionsURLKey, uniform type identifier, uti, [iOS] 앱이 지원하는 File Type 등록하고 처리하기, 등록, 처리


-

https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html#//apple_ref/doc/uid/TP40010411-SW1


CFBundleDocumentTypes 를 Info.plist 에 포함시켜야 한다.

이 key 에 대한 값은 dictionary 의 array 형태를 갖는다.

각 dictionary 는 처리할 파일에 대한 정보를 갖는다.

한 dictionary 에 여러 개의 파일 타입을 정의할 수도 있다. ( ex) old format & new format )



-

CFBundleDocumentTypes 에 연결되는 dictionary 는 다음의 값을 가질 수 있다.

     CFBundleTypeNames

     CFBundleTypeIconFiles : 이미지 리소스들에 대한 file name 를 array 형태로 갖는다.

     LSItemContentTypes : 파일 타입에 대한 UTI(Uniform Type Identifier) string 을 array 형태로 갖는다.

     LSHandlerRank : 해당 타입에 대한 owner 인지 아니면 open 만 지원하는건지를 명시한다.



-

LSItemContenTypes 는 아래 링크에서 찾아서 적용하면 된다.

https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html



-

ex)

<dict>

   <key>CFBundleTypeName</key>

   <string>My File Format</string>

   <key>CFBundleTypeIconFiles</key>

       <array>

           <string>MySmallIcon.png</string>

           <string>MyLargeIcon.png</string>

       </array>

   <key>LSItemContentTypes</key>

       <array>

           <string>com.example.myformat</string>

       </array>

   <key>LSHandlerRank</key>

   <string>Owner</string>

</dict>



-

https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/OpeningSupportedFileTypes.html#//apple_ref/doc/uid/TP40010412-SW1


실제 open 을 한 경우 AppDelegate 의 application:willFinishLaunchingWithOptions: 또는 application:didFinishLaunchingWithOptions: 가 불리게 되며, options 에 아래 key 값들에 값이 채워져 온다.


UIApplicationLaunchOptionsURLKey : 처리해야 할 파일의 NSURL 이 들어있다.

UIApplicationLaunchOptionsSourceApplicationKey : 앱을 연 app 의 bundle id 가 NSString 으로 들어있다.

UIApplicationLaunchOptionsAnnotationKey : file 을 열 때 관련된 property list 가 들어있다.



-

앱이 background 일 때는 didFinishLaunch 쪽이 안 불리고, 아래 callback 이 대신 불린다.


- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;




반응형

댓글