iOS: Add gemini:// protocol handling

This commit is contained in:
Shadowfacts 2020-09-27 22:56:36 -04:00
parent d188802480
commit ef47b59aab
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 29 additions and 1 deletions

View File

@ -16,6 +16,19 @@
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0</string> <string>1.0</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>net.shadowfacts.gemini</string>
<key>CFBundleURLSchemes</key>
<array>
<string>gemini</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1</string> <string>1</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>

View File

@ -14,13 +14,22 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow? var window: UIWindow?
let navigationManager = NavigationManager(url: URL(string: "gemini://gemini.circumlunar.space/")!) var navigationManager: NavigationManager!
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
let initialURL: URL
if let context = connectionOptions.urlContexts.first {
initialURL = context.url
} else {
initialURL = URL(string: "gemini://gemini.circumlunar.space/")!
}
navigationManager = NavigationManager(url: initialURL)
navigationManager.delegate = self navigationManager.delegate = self
// Create the SwiftUI view that provides the window contents. // Create the SwiftUI view that provides the window contents.
@ -34,6 +43,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
window.makeKeyAndVisible() window.makeKeyAndVisible()
} }
} }
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let context = URLContexts.first {
navigationManager.changeURL(context.url)
}
}
func sceneDidDisconnect(_ scene: UIScene) { func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system. // Called as the scene is being released by the system.