2014-10-02 75 views
0

我試圖從通知中心的今天擴展程序中打開應用程序,我嘗試過使用計劃URL,但似乎我無法使用是在擴展中,因爲:今天如何從iOS 8打開應用程序擴展

[UIApplication sharedapplication] 

不起作用。我該怎麼辦?

回答

2

這應該解決您的問題:

NSURL *url = [NSURL URLWithString:@"testMe://"]; 
[self.extensionContext openURL:url completionHandler:nil]; 
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") 
    } 
}