简体   繁体   中英

How to copy the file from other App to ma App's documents directory in iOS?

I create a App named Reader , and I try to read the text file via my App from the other Application , ex: read text file from google driver , e-mail , dropbox.

I reference the following link to add my App into "open in..." list when I press the text file on e-mail , google driver or dropbox.

How do I get my application to show up in the "Open in..." menu on iOS for a specific document type?

For example: I receive the file from e-mail like the following picture.

[ 在此处输入图片说明 ]

When I press on the text file , it show the content. And it show like the following picture when I press the share button on the upper right corner. And it can choose to open the text file via my App( Reader )

在此处输入图片说明

After I choose my Reader app , the Reader will open. And I want to read the content of text file. But I have no idea what to do...

How to read the content of text file after my Reader App open ?

Should I copy the text file to my App's documents directory first ? How to copy ? I didn't get the text file path or any object...

In your AppDelegate add the method:

func application(application: UIApplication, handleOpenURL url: NSURL) -> Bool { ... }

You will be passed the NSURL of the file which is being opened in your application, you can use that NSURL to access the file using something like NSString or NSData

// NSData 
init?(contentsOfURL url: NSURL)

// NSString 
convenience init?(contentsOfURL url: NSURL, encoding enc: UInt, error: NSErrorPointer)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM