-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSceneDelegate.swift
More file actions
96 lines (70 loc) · 2.91 KB
/
SceneDelegate.swift
File metadata and controls
96 lines (70 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// SceneDelegate.swift
// FruitAppClip
//
// Created by Jonathan Wesfield on 12/07/2020.
//
import UIKit
import AppClip
import CoreLocation
import AppsFlyerLib
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
// Must for AppsFlyer attrib
AppsFlyerLib.shared().continue(userActivity, restorationHandler: nil)
}
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
if let userActivity = connectionOptions.userActivities.first {
self.scene(scene, continue: userActivity)
}
return
}
func sceneDidDisconnect(_ scene: UIScene) {
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Start the SDK
AppsFlyerLib.shared().start()
}
func sceneWillResignActive(_ scene: UIScene) {
}
func sceneWillEnterForeground(_ scene: UIScene) {
}
func sceneDidEnterBackground(_ scene: UIScene) {
}
func verifyUserLocation(activity: NSUserActivity?) {
// Guard against faulty data.
guard activity != nil else { return }
guard activity?.activityType == NSUserActivityTypeBrowsingWeb else { return }
guard let payload = activity?.appClipActivationPayload else { return }
guard let incomingURL = activity?.webpageURL else { return }
// Create a CLRegion object.
guard let region = location(from: incomingURL) else {
return
}
// Verify that the invocation happened at the expected location.
payload.confirmAcquired(in: region) { (inRegion, error) in
guard let confirmationError = error as? APActivationPayloadError else {
if inRegion {
print("The location of the NFC tag matches the user's location.")
} else {
print("The location of the NFC tag doesn't match the records")
}
return
}
if confirmationError.code == .doesNotMatch {
print("The scanned URL wasn't registered for the app clip")
} else {
print("The user denied location access, or the source of the app clip’s invocation wasn’t an NFC tag or visual code.")
}
}
}
func location(from url:URL) -> CLRegion? {
let coordinates = CLLocationCoordinate2D(latitude: 37.334722,
longitude: 122.008889)
return CLCircularRegion(center: coordinates,
radius: 100,
identifier: "Apple Park")
}
}