चाल स्थानीय रूप से फ़ाइल को एक .txt फ़ाइल के रूप में सहेजना है और फिर UIDocumentInteractionController
का उपयोग करके इसे खोलना है। अपने कोड में कहीं से भी
import UIKit
class ViewController: UIViewController, UIDocumentInteractionControllerDelegate {
var interactionController: UIDocumentInteractionController?
func openInPages(body: String, title: String) throws {
// create a file path in a temporary directory
let fileName = "\(title).txt"
let filePath = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent(fileName)
// save the body to the file
try body.writeToFile(filePath, atomically: true, encoding: NSUTF8StringEncoding)
// for iPad to work the sheet must be presented from a bar item, retrieve it here as below or create an outlet of the Export bar button item.
let barButtonItem = navigationItem.leftBarButtonItem!
// present Open In menu
interactionController = UIDocumentInteractionController(URL: NSURL(fileURLWithPath: filePath))
interactionController?.presentOptionsMenuFromBarButtonItem(barButtonItem, animated: true)
}
}
कॉल openInPages
(जैसे जब उपयोगकर्ता एक Export
बार बटन आइटम प्रेस):: यहाँ पूर्ण नमूना कोड है
openInPages("This will be the body of the new document", title: "SomeTitle")
आपको बहुत बहुत धन्यवाद, मैंने आपकी विधि की कोशिश की (मैंने ठीक उसी कोड का उपयोग किया था, सिवाय इसके कि मुझे 'ओपन इनपेज' को कॉल करना था: '{ ओपन इनपेज (flowNote.text, शीर्षक: "नोटफ्लो, 1 अगस्त से निर्यात किया गया)" } पकड़ें _ { प्रिंट ("पेजों में खोलने में असमर्थ।") } 'और फ़ंक्शन को कॉल करते समय कुछ भी नहीं हुआ (मैंने इसे अपने भौतिक आईपैड एयर और आईफोन 6 सिम्युलेटर में चलाया)। कंसोल में कई गैर-गंभीर त्रुटियां दिखाई दीं, ऐसा लगता है एक्सकोड को एयरड्रॉप मेनू में बाधाओं का एक गुच्छा तोड़ना पड़ा। (?)। इसलिए मुझे यहां कुछ मदद की ज़रूरत है! – owlswipe
आप शायद ऐप लाइफसाइक्ल में जल्द ही विधि को कॉल करने का प्रयास कर रहे हैं। अद्यतन कोड – Casey
मुझे नहीं लगता कि इसे अपने नए कोड परिणामों की तरह viewdidload से कॉल करने में कोई त्रुटि नहीं होती है, लेकिन इसके परिणामस्वरूप शेयर संवाद poppi नहीं होता है बिल्कुल ऊपर। (ध्यान दें: टूटा हुआ बाधा त्रुटि संदेश अभी भी कंसोल में पॉप अप करते समय ठीक उसी तरह कॉल करते हैं जब आप viewdidload से करते हैं।) – owlswipe