This question already has an answer here:
In my app, I designed a new encrypted type data as attachment to the mail. When I receive the same type of attachment(filename.filetype) from another user, I want the attachment from mail to open in my app. I went through the action extensions tutorials. But, what is missing is, how can I open that particular type of attachment using my swift app. I get the answers in Obj-C as well as the previous versions of iOS. I am seeking an answer in iOS8, Swift to handle the file.
Here is my info.plist
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>pvt file</string>
<key>UTTypeIdentifier</key>
<string>com.pryvateBeta.pvt</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>pvt</string>
</dict>
</dict>
</array>
<key>CFBundleDocumentsType</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>pvt file</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.pryvateBeta.pvt</string>
</array>
</dict>
</array>
Here is my AppDelegate
func application(application: UIApplication, openURL Url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
let encrypteddata = NSData(contentsOfURL: Url)
return true}
First of all you need to declare the file type your app will handle in your apps
Info.plist
.For instance the configuration shown below declares that the app is able to open
.lumenconfig
files which are basically XML. See this for more info about the declarations.If you use a custom type like I do in the above example you also need to declare that type. See this for more information about declaring your own type
Then in your app delegate implement a handler to handle the file: