백그라운드 읽기 기능 지원
Associated Domain을 등록한다.(유니버셜 링크의 요구 사항)
AppDelegate에서 다음 메소드를 구현한다.
application(_:continue:restorationHandler:)
NSUserActivity의 ndefMessagePayload 프로퍼티에 접근한다.
Example Code
import CoreNFC
@UIApplication
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
// activity 타입 검증
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb else {
return false
}
// ndefMessage 가져오기
let ndefMessage = userActivity.ndefMessagePayload
// ndefMessage 검증
// 백그라운드 읽기에서 나온 activity가 아니면, 페이로드가 1개 뿐이고, type이 empty다.
guard ndefMessage.records.count > 0,
ndefMessage.records[0].typeNameFormat != .empty else {
return false
}
return true
}
}
만약 URL이 유니버셜 링크가 아닌경우에도, 몇가지 URL은 처리할 수 있다.