IOS allows its App to be displayed in the list of other apps
For applications such as Baidu online storage, you can use the following applications to open files. My jpg in the red box below is an example of my work. Because no Icon is provided in the example, the default icon is displayed.
The following are the main steps and code for this example. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + signature + CjxwPgoxoaLU2s/uxL + signature "http://www.bkjia.com/uploads/allimg/141104/0401514a5-1.png" width = "12" height = "12" alt = "view CODE on CODE">
- CFBundleDocumentTypes
-
-
- CFBundleTypeIconFiles
-
- Icon@2x.png
- Icon.png
-
- CFBundleTypeName
- Molecules Structure File
- CFBundleTypeRole
- Viewer
- LSHandlerRank
- Owner
- LSItemContentTypes
-
- Com.fzrong.jpg
- Org. gnu. gnu-zip-archive
-
-
-
- UTExportedTypeDeclarations
-
-
- UTTypeConformsTo
-
- Public. plain-text
- Public. text
-
- UTTypeDescription
- Molecules Structure File
- UTTypeIdentifier
- Com.fzrong.jpg
- UTTypeTagSpecification
-
- Public. filename-extension
- Jpg
- Public. mime-type
- Image/jpg
-
-
- This tells the system that you can open the jpg file type.
2. When you open your app, you need to capture the file path of the Resource:
Add the following code to Appdelegate:
[Objc]View plaincopy
- -(BOOL) application :( UIApplication *) application openURL :( NSURL *) url sourceApplication :( NSString *) sourceApplication annotation :( id) annotation
- {
- If (url! = Nil ){
- NSString * path = [url absoluteString];
- NSMutableString * string = [[NSMutableString alloc] initWithString: path];
- If ([path hasPrefix: @ "file: //"]) {
- [String replaceOccurrencesOfString: @ "file: //" withString: @ "" options: NSCaseInsensitiveSearch range: NSMakeRange (0, path. length)];
- }
- [Self. viewController openPng: string];
-
- }
-
- Return YES;
- }
Remove the file: // file path header. Otherwise, the resource cannot be found.
3. Open jgp display in your ViewController:
[Objc]View plaincopy
- -(Void) openPng :( NSString *) string
- {
- UIImage * image = [[UIImage alloc] initWithContentsOfFile: string];
- Float width = image. size. width;
- Float height = image. size. height;
- If (length> 320 ){
- Height = (height/width) * 300;
- Length = 300;
- }
-
- CGRect frame = CGRectMake (0, 20, width, height );
- ImageView. frame = frame;
-
- ImageView. image = image;
-
- }
The following figure shows the effect after opening:Html
Http://stackoverflow.com/questions/20869815/open-file-from-local-file-system-with-default-application-ios