共享扩展 - 未调用beginRequestWithExtensionContext

时间:2015-04-28 08:04:19

标签: ios ios8-share-extension

我有一个拥有自定义用户界面的iOS应用的共享扩展程序。运行扩展程序时,将加载故事板并显示UI,但不会调用beginRequestWithExtensionContext

(简化)视图控制器代码:

class ShareViewController: UIViewController, NSExtensionRequestHandling {

    // This is called…
    override func viewDidLoad() {
        super.viewDidLoad() 
    }

    // …but this isn't!
    override func beginRequestWithExtensionContext(context: NSExtensionContext) {            
        println("beginRequestWithExtensionContext")
    }
}

NSExtensionAttributes

<dict>
    <key>NSExtensionAttributes</key>
    <dict>
        <key>NSExtensionActivationRule</key>
        <dict>
            <key>NSExtensionActivationSupportsImageWithMaxCount</key>
            <integer>1</integer>
        </dict>
    </dict>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.share-services</string>
    <key>NSExtensionMainStoryboard</key>
    <string>Share</string>
</dict>
</plist>

关于为什么beginRequestWithExtensionContext可能没有被调用的任何想法?

1 个答案:

答案 0 :(得分:2)

好的,所以经过2天的向后和向前,我在SO上发布问题后想出了30分钟!所以,如果其他人有同样的问题......

故事板有一个UINavigationController作为其初始视图控制器,因此beginRequestWithExtensionContext当然是针对ShareViewController而不是UINavigationController

我已将class ShareNavigationController: UINavigationController, NSExtensionRequestHandling { override func beginRequestWithExtensionContext(context: NSExtensionContext) { super.beginRequestWithExtensionContext(context) (self.topViewController as! ShareViewController).handleContext(context) } } 子类化以解决此问题:

CREATE TABLE accounts(
    accountNo int(100) NOT NULL AUTO_INCREMENT,
    accountType VARCHAR(100) NOT NULL,
    firstName VARCHAR(50) NOT NULL,
    lastName VARCHAR(60) NOT NULL,
    birthdate DATE NOT NULL,
    gender VARCHAR(7),
    city VARCHAR(50) NOT NULL,
    street VARCHAR(50),
    cellPhone VARCHAR(10),
    CONSTRAINT PRIMARY KEY(accountNo)
);