当前位置: 动力学知识库 > 问答 > 编程问答 >

core data - How to open in a IOS App a specific view based on a file extension that an user have on a attachment (swift)

问题描述:

Good morning everyone I need your help (again); I have created an application that generates to files with two different file extensions as listed below:

  1. First extension: .myexport (which is use to share all the information stored in the local core-data storage)
  2. Second extension: .myshare (which is use to share a specific record from the local core-data storage).

The main idea in here is that an user can send by email a file if he wants to share that information with another device (a friend device for example), so when the other user receives the email with the attachment, this should open in View A (base on the image below) and import the file content in the new device. But also the user can send as attachment a specific record to another user and when the second user receives the email and opens the attachments the file should open in View B (based on the image below) so the user won't import this information but can review and modify the information and send it back to the original person.

The idea of the 2 files is because the application must do stuff differently depending of the information received.

If this is possible may I ask you for some code sample of how to achieve this?

Here is the image sample of how the storyboard is organized.

Thanks in advances for your help.

网友答案:

Hi I figure it out based on a post related to push notification.

Here is the code that I use to deal with the attachment part; the change is in the AppDelegate.swift file

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
        //url contains a URL to the file your app shall open


    do {
        if (url.path!.hasSuffix("fileext1")){
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewControllerWithIdentifier("AddComment") as! AddCommentViewController
            vc.imported = true
            window?.rootViewController = vc
        }
        else if (url.path!.hasSuffix("fileext2")){

            let result = try General.SaveXmlToCoreData(url.path!)
        }
    }
    catch let error as NSError {
        NSLog(error.localizedDescription)
    }

    return true
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: