너무 헤매서 정리해놓는 ios 16.5.1 , xcode 14.3.1 기준 유니버셜링크 적용
1. 애플 개발자 사이트 identifier에 Associated Domains 체크
2. xcode 에서 target > signing&capabilities 에서 associated domain 추가
applinks:domain.com
webcredentials:domain.com
추가
3. apple-app-site-association 만들기
아래 사이트에 잘 정리되어져있음
참조 : https://sangheon.com/유니버설-링크-universal-links/
유니버설 링크 (Universal Links)
유니버설 링크(Universal Links) 앱에서 유니버설 링크를 지원하기 위해서는 apple-app-site-association(AASA) 파일을 작성해서 웹 서버에 올려두는 작업이 필요합니다. Apple JSON Metadata file iOS 12 이전 1 2
sangheon.com
aasa 파일을 json 형식에서 사이트 인증서 이용해 signing 을 해서 저장 후
http://domain.com/.well-known/apple-app-site-association 에 업로드를 해야한다
주소창에 http://domain.com/.well-known/apple-app-site-association 입력해 다운이 되면 잘 반영 된것이고
4. 코드 추가 :: 난 SceneDelegate를 사용하고 있어 SceneDelegate 에서 작성
//앱 종료되있다가 유니버셜링크로 인해 실행될 때
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let firstUrlContext = connectionOptions.urlContexts.first {
universallinkurl = firstUrlContext.url.absoluteString
}
}
근데 애플 개발자 문서를 보면
guard let userActivity = connectionOptions.userActivities.first,
userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let incomingURL = userActivity.webpageURL,
let components = NSURLComponents(url: incomingURL, resolvingAgainstBaseURL: true) else {
return
}
// Check for specific URL components that you need.
guard let path = components.path,
let params = components.queryItems else {
return
}
print("path = \(path)")
이렇게 되어져있는데 난 userActivity를 받아오지 못했다....
이유를 아시는 분은 댓글로 알려주시면 감사드리겠습니다....
//앱 살아있다가 유니버셜링크로 인해 실행될 때
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else { return }
for urlContext in URLContexts {
let urlToOpen = urlContext.url
}
}
애플 개발자 문서에 나와있는대로 하면 안되는 원인은 모르겠으나
다행히 주소는 받아옴
다 설정했으면 앱 삭제 > 사파리 데이터 지우기 > 재부팅 > 앱설치 하고 테스트~
'iOS - Swift' 카테고리의 다른 글
[ios/swift] APNS p12로 내보내기 (1) | 2024.09.30 |
---|---|
[swift] 다크모드일때 상태바 글자 안보이는 오류 (0) | 2023.07.19 |
[swift] wkwebview decidePolicyFor not called (0) | 2023.06.26 |
[스위프트/swift] wkwebview 에서 window.close() 처리 (0) | 2023.05.22 |
[스위프트/swift] wkwebview google login 오류 - null is not an object (evaluating 'window.opener.postMessage') (0) | 2023.05.22 |