且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在IOS应用程序中基于用户对附件(swift)的文件扩展名打开特定视图

更新时间:2022-11-28 12:04:33

这是我用来处理附件部分的代码;更改在AppDelegate.swift文件中

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
}