簡體   English   中英

分享分機 ios swift

[英]Share extension ios swift

我創建了一個帶有一些按鈕的共享擴展,並繼承了UIViewcontroller的擴展。 當我創建這些UIButtons@IBAction時,它永遠不會在單擊按鈕時被調用。

import UIKit
import Social

class ShareViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    
//    override func isContentValid() -> Bool {
//        // Do validation of contentText and/or NSExtensionContext attachments here
//        return true
//    }
//
//    override func didSelectPost() {
//        // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
//    
//        // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
//        self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
//    }
//
//    override func configurationItems() -> [Any]! {
//        // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
//        return []
//    }

    @IBAction func btnBackClicked(_ sender: Any) {
        self.dismiss(animated: true, completion: nil)
    }
    @IBAction func btnCancleClicked(_ sender: Any) {
        self.dismiss(animated: true, completion: nil)
    }
    @IBAction func btnSaveClicked(_ sender: Any) {
        
    }
}

我認為正在調用您的按鈕操作,只是調用self.dismiss(animated: true, completion: nil)實際上不會關閉您的共享擴展。

參考這個答案,你應該使用:

self.extensionContext.:completeRequest(returningItems, nil: completionHandler: nil)

或者

self.extensionContext.:cancelRequest(withError:NSError(domain. Bundle.main,bundleIdentifier:, code: 0))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM