2014-06-22 7 views
15

iOS의 릴리스 노트에 기록으로 앱 확장에서의 OpenURL을 사용하는 것이 가능해야한다 8 베타 2 : 그러나의 OpenURL에서 앱 확장

enter image description here

내가 엑스 코드 (6)에이 API를 (사용하려고 베타 2) 나는 다음과 같은 오류 얻을 :

enter image description here

베타 2는 정말이 문제를 해결 여부?

이 코드를 사용할 수 있습니다

답변

41

:

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

은 API 문서 : openURL:completionHandler:

하기이 질문에 참조 할 수

: 이 openURL not work in Action Extension

+0

대단히 감사합니다. 그것은 완벽하게 작동합니다. –

+0

@MassimoPiazza openURL 문장을 추가 할 때 어떤 유형의 확장 기능을 사용합니까? 액션 익스텐션에서 시도했지만 실패했습니다. 오늘 확장 기능에서만 성공합니다. 어떤 결과가 있습니까? –

+0

오늘의 확장 기능 –

0

허용 솔루션은 Today extensions에서 작동하는 다른 확장 유형을위한 Swift 3.1 (iOS10에서 테스트 됨)의 작업 솔루션 :

,

당신은 다음 반응식 자신의 URL을 생성 당신의 ViewController에이 기능을 추가하고 당신이 문제없이 확장에 UIApplication.sharedApplication.openURL을 사용할 수 있다는 것 아이폰 OS 11에서 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

로를 호출해야합니다.