Search code examples
objective-ctitaniumappceleratoruidocumentinteraction

Document Interaction Controller on Titanium


Is there a way to toggle the DocumentInteractionController on Titanium i'm not finding it in any way

i think this is what i need

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL) fileURL
    usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {

    UIDocumentInteractionController *interactionController =
        [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    interactionController.delegate = interactionDelegate;

    return interactionController;
}

Solution

  • You're looking for Ti.UI.iOS.createDocumentViewer(). That API uses UIDocumentInteractionController under the covers.

    var win = Ti.UI.createWindow({
        backgroundColor: '#fff'
    });
    win.open();
    
    // Download a PDF.
    var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'casestudy_bracket.pdf'),
        client = Ti.Network.createHTTPClient({
        onload: function() {
            // Open a doc viewer.
            var docViewer = Ti.UI.iOS.createDocumentViewer({
                url: file.nativePath
            });
            docViewer.show({ animated: true });
        },
        onerror: function() {
            alert('Well, shoot.')
        }
    });
    client.open('GET', 'http://www.appcelerator.com.s3.amazonaws.com/pdf/casestudy_bracket.pdf');
    client.file = file;
    client.send();