2014-06-22 18 views
15

Su iOS 8 beta 2 dovrebbe essere possibile utilizzare OpenURL da estensione per applicazioni come scritto nelle note di rilascio:openURL da App Extension

enter image description here

tuttavia quando provo ad usare questa API (su Xcode 6 beta 2) ottengo il seguente errore:

enter image description here

beta 2 davvero risolto questo problema o no?

risposta

41

è possibile utilizzare questo codice:

[self.extensionContext openURL:url completionHandler:^(BOOL success) { 
     NSLog(@"fun=%s after completion. success=%d", __func__, success); 
    }]; 

il documento API: openURL:completionHandler:

si potrebbe anche riferirsi a questa domanda: openURL not work in Action Extension

+0

Grazie mille! Funziona perfettamente –

+0

@MassimoPiazza Quale tipo di estensione usi quando aggiungi la frase openURL? Lo provo con l'estensione Action ma non ci sono riuscito. Ho solo successo nell'estensione di oggi. Che risultato hai? –

+0

Sto lavorando su Today Extensions –

0

soluzione accettata funziona solo in Today extensions, un soluzione di lavoro in Swift 3.1 (testato in iOS10) per altri tipi di estensione:

È necessario creare il proprio URL Scheme, quindi aggiungere questa funzione al vostro ViewController e chiamarla con openURL("myScheme://myIdentifier")

// Function must be named exactly like this so a selector can be found by the compiler! 
// Anyway - it's another selector in another instance that would be "performed" instead. 
func openURL(_ url: URL) -> Bool { 
    var responder: UIResponder? = self 
    while responder != nil { 
     if let application = responder as? UIApplication { 
      return application.perform(#selector(openURL(_:)), with: url) != nil 
     } 
     responder = responder?.next 
    } 
    return false 
} 
0

in IOS 11 sembra che è possibile utilizzare UIApplication.sharedApplication.openURL nelle estensioni, senza il problema.