Skip to content

Commit 48ae02b

Browse files
committed
Implemented universal links
- removed avivscr schema and dependancy
1 parent 28c511e commit 48ae02b

File tree

5 files changed

+55
-39
lines changed

5 files changed

+55
-39
lines changed

GoInfoGame/GoInfoGame.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@
519519
C77AACA52E447364006713B2 /* GoogleService-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
520520
C77EEBCE2DE59D3200494CB4 /* UndoMerge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UndoMerge.swift; sourceTree = "<group>"; };
521521
C78737AE2E4C9E3200289D13 /* FloatingLabelTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloatingLabelTextField.swift; sourceTree = "<group>"; };
522+
C787EF162E9676CC00BEF0A6 /* GoInfoGame.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoInfoGame.entitlements; sourceTree = "<group>"; };
522523
C7927B532E42363000A7A34E /* XCAssets+Generated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCAssets+Generated.swift"; sourceTree = "<group>"; };
523524
C7A922242E45C36D00705E21 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
524525
C7BA83532E3C9C3600755BA7 /* QuestSyncButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = QuestSyncButton.swift; path = GoInfoGame/UI/Map/QuestSyncButton.swift; sourceTree = SOURCE_ROOT; };
@@ -1561,6 +1562,7 @@
15611562
FAD5C4F12AFCBE700040C61A /* GoInfoGame */ = {
15621563
isa = PBXGroup;
15631564
children = (
1565+
C787EF162E9676CC00BEF0A6 /* GoInfoGame.entitlements */,
15641566
FA18CADE2CC7CD46008247F2 /* Kartaview */,
15651567
FAFDA2092C6F589900ECEAE9 /* UserProfile */,
15661568
FAFDA1FB2C6D321500ECEAE9 /* Login */,
@@ -2893,6 +2895,7 @@
28932895
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
28942896
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
28952897
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
2898+
CODE_SIGN_ENTITLEMENTS = GoInfoGame/GoInfoGame.entitlements;
28962899
CODE_SIGN_IDENTITY = "Apple Development";
28972900
CODE_SIGN_STYLE = Automatic;
28982901
CURRENT_PROJECT_VERSION = 1;
@@ -2958,6 +2961,7 @@
29582961
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
29592962
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
29602963
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
2964+
CODE_SIGN_ENTITLEMENTS = GoInfoGame/GoInfoGame.entitlements;
29612965
CODE_SIGN_IDENTITY = "Apple Development";
29622966
CODE_SIGN_STYLE = Automatic;
29632967
CURRENT_PROJECT_VERSION = 1;

GoInfoGame/GoInfoGame.xcodeproj/xcshareddata/xcschemes/GoInfoGame.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
</Testables>
6060
</TestAction>
6161
<LaunchAction
62-
buildConfiguration = "Debug"
62+
buildConfiguration = "Release"
6363
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
6464
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
6565
launchStyle = "0"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.developer.associated-domains</key>
6+
<array>
7+
<string>applinks:www.srikanthvoonna.co.in</string>
8+
<string>applinks:srikanthvoonna.co.in</string>
9+
</array>
10+
</dict>
11+
</plist>

GoInfoGame/GoInfoGame/Info.plist

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,7 @@
1111
<string>com.vindago.goinfogame</string>
1212
<key>CFBundleURLSchemes</key>
1313
<array>
14-
<string>avivscr</string>
15-
</array>
16-
</dict>
17-
<dict>
18-
<key>CFBundleTypeRole</key>
19-
<string>Editor</string>
20-
<key>CFBundleURLIconFile</key>
21-
<string></string>
22-
<key>CFBundleURLName</key>
23-
<string>tech.opentoall.aviv.scoutroute</string>
24-
<key>CFBundleURLSchemes</key>
25-
<array>
26-
<string>avivscr</string>
14+
<string>goinfogame</string>
2715
</array>
2816
</dict>
2917
</array>

GoInfoGame/GoInfoGame/SceneDelegate.swift

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
1414

1515
@AppStorage("loggedIn") private var loggedIn: Bool = false
1616

17-
var posmLoginView: PosmLoginView? = nil
18-
1917
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
2018
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
2119
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
@@ -40,7 +38,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
4038
window.rootViewController = UIHostingController(rootView: contentView)
4139
self.window = window
4240
window.makeKeyAndVisible()
43-
self.posmLoginView = contentView
41+
}
42+
43+
if let userActivity = connectionOptions.userActivities.first,
44+
userActivity.activityType == NSUserActivityTypeBrowsingWeb,
45+
let incomingURL = userActivity.webpageURL {
46+
handleUniversalLink(incomingURL)
4447
}
4548
}
4649
}
@@ -72,34 +75,44 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
7275
// Use this method to save data, release shared resources, and store enough scene-specific state information
7376
// to restore the scene back to its current state.
7477
}
78+
79+
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
80+
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
81+
let incomingURL = userActivity.webpageURL else {
82+
return
83+
}
84+
85+
handleUniversalLink(incomingURL)
86+
}
87+
88+
private func handleUniversalLink(_ url: URL) {
89+
print("Universal Link called")
90+
guard !loggedIn else {
91+
debugPrint("user is already login")
92+
return // user is already login
93+
}
94+
95+
guard let refreshToken = url.queryParameters?["code"] else {
96+
debugPrint("invalid scheme url format")
97+
return // invalid url format
98+
}
99+
100+
APIConfiguration.shared.environment = APIEnvironment(rawValue: url.queryParameters?["env"]?.lowercased() ?? "prod") ?? .production
101+
guard let window = self.window,
102+
let hostingController = window.rootViewController as? UIHostingController<PosmLoginView> else {
103+
debugPrint("PosmLoginView not found")
104+
return
105+
}
106+
let loginView = hostingController.rootView
107+
loginView.viewModel.loginWithRefreshToken(refreshToken: refreshToken)
108+
}
75109

76110
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
77111
print("Open contexts called")
78112
// gaurd and get the first URL
79113
guard let url = URLContexts.first?.url else { return }
80114

81-
if url.scheme == "avivscr" {
82-
guard !loggedIn else {
83-
debugPrint("user is already login")
84-
return // user is already login
85-
}
86-
87-
guard let refreshToken = url.queryParameters?["code"] else {
88-
debugPrint("invalid scheme url format")
89-
return // invalid url format
90-
}
91-
92-
APIConfiguration.shared.environment = APIEnvironment(rawValue: url.queryParameters?["env"]?.lowercased() ?? "prod") ?? .production
93-
guard let window = self.window,
94-
let hostingController = window.rootViewController as? UIHostingController<PosmLoginView> else {
95-
debugPrint("PosmLoginView not found")
96-
return
97-
}
98-
let loginView = hostingController.rootView
99-
loginView.viewModel.loginWithRefreshToken(refreshToken: refreshToken)
100-
} else {
101-
NotificationCenter.default.post(name: .init("HandleOAuthRedirect"), object: url)
102-
}
115+
NotificationCenter.default.post(name: .init("HandleOAuthRedirect"), object: url)
103116
}
104117
}
105118

0 commit comments

Comments
 (0)