如何从今天的iOS 8开放应用程序扩展

时间:2014-10-02 12:37:12

标签: ios8

我正在尝试从通知中心的今天扩展程序中打开应用程序,我已尝试使用该方案网址,但似乎我无法使用在扩展程序中,因为:

[UIApplication sharedapplication] 

不起作用。我怎么做?

2 个答案:

答案 0 :(得分:2)

这可以解决您的问题:

NSURL *url = [NSURL URLWithString:@"testMe://"];
[self.extensionContext openURL:url completionHandler:nil];

答案 1 :(得分:0)

在扩展程序

中添加按钮到故事板

添加CFBundleURLSchemes,以便您可以使用网址“weatherapp:”打开应用

致电openURL

@IBAction func buttonOpen_Action(sender: AnyObject) {
    /*
    Add to APP Info.plist
    <plist version="1.0">
        <dict>
        <key>CFBundleURLTypes</key>
        <array>
            <dict>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>weatherapp</string>
                </array>
            </dict>
        </array>
        </dict>
    </plist>

    */
    let context = self.extensionContext
    if let url = NSURL(string:"weatherapp:"){

        context?.openURL(url, completionHandler: { (Bool) -> Void in
            print("weatherapp:open done.")
        })

    }else{
        print("ERROR: weatherapp: not supported")
    }
}