How do I launch an Apple Pages document from my iOS application?

436 Views Asked by At

I have a pages document in my iOS applications bundle. I'd like to open this document directly with Apple's Pages iOS app. I know I have to add schemes in info.plist under LSApplicationQueriesSchemes. But i'm really just guessing what I should add. I have tried "pages"//" and "com.apple.pages://" and neither of these work.

If I try MS Word, it works!

UIApplication.shared.open(URL.init(string: "word://hello.doc")!, options: [: ]) { (result) in
    print(result)
}

When I try:

UIApplication.shared.canOpenURL(URL.init(string: "pages://hello.pages")!)

I get the following error:

canOpenURL: failed for URL: "pages://hello.pages" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"

When i google this error code, I find it means kLSApplicationNotFoundErr. Is it possible to open a .pages document this way? Or do u have to use UIDocumentInteractionController?

1

There are 1 best solutions below

1
Kasey On

The code to get a button to link to a URL is...

@IBAction func linkTapped(_ sender: UIButton) {
    if let url = NSURL(string: 
"https://www.radiusapp.co/blog/end-user-license- 
agreement"){
        UIApplication.shared.open(url as URL)
    }
}

Since you're technically linking to URL, I believe that this should work. If not, would linking to a Google doc be an option?? I hope this helps!