diff --git a/Delta.xcodeproj/project.pbxproj b/Delta.xcodeproj/project.pbxproj index eddccca..07a2a0e 100644 --- a/Delta.xcodeproj/project.pbxproj +++ b/Delta.xcodeproj/project.pbxproj @@ -134,6 +134,7 @@ BFB359452278FD8100CFD920 /* N64DeltaCore_RSP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BFB359422278FD6800CFD920 /* N64DeltaCore_RSP.framework */; }; BFB359462278FD8100CFD920 /* N64DeltaCore_RSP.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BFB359422278FD6800CFD920 /* N64DeltaCore_RSP.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; BFBAB2E31EB685A2004E0B0E /* DeltaCoreProtocol+Delta.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBAB2E21EB685A2004E0B0E /* DeltaCoreProtocol+Delta.swift */; }; + BFC1F2CC22F9515F00606A45 /* CopyDeepLinkActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC1F2CB22F9515F00606A45 /* CopyDeepLinkActivity.swift */; }; BFC3628021ADE2BA00EF2BE6 /* UIAlertController+Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC3627F21ADE2BA00EF2BE6 /* UIAlertController+Error.swift */; }; BFC6F7B81F435BC500221B96 /* Input+Display.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC6F7B71F435BC500221B96 /* Input+Display.swift */; }; BFC9B7391CEFCD34008629BB /* CheatsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC9B7381CEFCD34008629BB /* CheatsViewController.swift */; }; @@ -314,6 +315,7 @@ BFB359422278FD6800CFD920 /* N64DeltaCore_RSP.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = N64DeltaCore_RSP.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BFBAB2E21EB685A2004E0B0E /* DeltaCoreProtocol+Delta.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DeltaCoreProtocol+Delta.swift"; sourceTree = ""; }; BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SNESDeltaCore.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + BFC1F2CB22F9515F00606A45 /* CopyDeepLinkActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopyDeepLinkActivity.swift; sourceTree = ""; }; BFC3627F21ADE2BA00EF2BE6 /* UIAlertController+Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertController+Error.swift"; sourceTree = ""; }; BFC6F7B71F435BC500221B96 /* Input+Display.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Input+Display.swift"; sourceTree = ""; }; BFC9B7381CEFCD34008629BB /* CheatsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheatsViewController.swift; sourceTree = ""; }; @@ -462,6 +464,7 @@ children = ( BF525EE91FF6CD12004AA849 /* DeepLink.swift */, BF525EE71FF5F370004AA849 /* DeepLinkController.swift */, + BFC1F2CB22F9515F00606A45 /* CopyDeepLinkActivity.swift */, ); path = "Deep Linking"; sourceTree = ""; @@ -1035,6 +1038,7 @@ BFAA1FED1B8AA4FA00495943 /* Settings.swift in Sources */, BFA0D1271D3AE1F600565894 /* GameViewController.swift in Sources */, BF59428A1E09BC8B0051894B /* _SaveState.swift in Sources */, + BFC1F2CC22F9515F00606A45 /* CopyDeepLinkActivity.swift in Sources */, BF5942801E09BC830051894B /* SaveState.swift in Sources */, BF59428E1E09BCFB0051894B /* ImportController.swift in Sources */, BF13A7581D5D2FD9000BB055 /* EmulatorCore+Cheats.swift in Sources */, diff --git a/Delta/AppDelegate.swift b/Delta/AppDelegate.swift index 564841a..e53bd0a 100644 --- a/Delta/AppDelegate.swift +++ b/Delta/AppDelegate.swift @@ -111,6 +111,10 @@ extension AppDelegate { return DropboxService.shared.handleDropboxURL(url) } + else if url.scheme?.lowercased() == "delta" + { + return self.deepLinkController.handle(.url(url)) + } return false } diff --git a/Delta/Deep Linking/CopyDeepLinkActivity.swift b/Delta/Deep Linking/CopyDeepLinkActivity.swift new file mode 100644 index 0000000..3dfc956 --- /dev/null +++ b/Delta/Deep Linking/CopyDeepLinkActivity.swift @@ -0,0 +1,53 @@ +// +// CopyDeepLinkActivity.swift +// Delta +// +// Created by Riley Testut on 8/5/19. +// Copyright © 2019 Riley Testut. All rights reserved. +// + +import UIKit + +extension UIActivity.ActivityType +{ + static let copyDeepLink = UIActivity.ActivityType("com.rileytestut.Delta.CopyDeepLink") +} + +class CopyDeepLinkActivity: UIActivity +{ + override class var activityCategory: UIActivity.Category { + return .action + } + + override var activityType: UIActivity.ActivityType? { + return .copyDeepLink + } + + override var activityTitle: String? { + return NSLocalizedString("Copy Deep Link", comment: "") + } + + override var activityImage: UIImage? { + return UIImage(named: "Link") + } + + override func canPerform(withActivityItems activityItems: [Any]) -> Bool + { + if activityItems.contains(where: { $0 is Game }) + { + return true + } + else + { + return false + } + } + + override func prepare(withActivityItems activityItems: [Any]) + { + guard let game = activityItems.first(where: { $0 is Game }) as? Game else { return } + + let deepLink = URL(action: .launchGame(identifier: game.identifier)) + UIPasteboard.general.url = deepLink + } +} diff --git a/Delta/Deep Linking/DeepLink.swift b/Delta/Deep Linking/DeepLink.swift index cb617e3..2395d9a 100644 --- a/Delta/Deep Linking/DeepLink.swift +++ b/Delta/Deep Linking/DeepLink.swift @@ -12,16 +12,12 @@ extension URL { init(action: DeepLink.Action) { - var components = URLComponents() - components.host = action.type.rawValue - switch action { - case .launchGame(let identifier): components.path = identifier + case .launchGame(let identifier): + let deepLinkURL = URL(string: "delta://\(action.type.rawValue)/\(identifier)")! + self = deepLinkURL } - - let url = components.url! - self = url } } diff --git a/Delta/Game Selection/GameCollectionViewController.swift b/Delta/Game Selection/GameCollectionViewController.swift index 6586b19..1eba284 100644 --- a/Delta/Game Selection/GameCollectionViewController.swift +++ b/Delta/Game Selection/GameCollectionViewController.swift @@ -585,7 +585,9 @@ private extension GameCollectionViewController print(error) } - let activityViewController = UIActivityViewController(activityItems: [symbolicURL], applicationActivities: nil) + let copyDeepLinkActivity = CopyDeepLinkActivity() + + let activityViewController = UIActivityViewController(activityItems: [symbolicURL, game], applicationActivities: [copyDeepLinkActivity]) activityViewController.completionWithItemsHandler = { (activityType, finished, returnedItems, error) in do { diff --git a/Delta/Supporting Files/Info.plist b/Delta/Supporting Files/Info.plist index 8ffff72..f2e1b65 100644 --- a/Delta/Supporting Files/Info.plist +++ b/Delta/Supporting Files/Info.plist @@ -149,6 +149,16 @@ db-f5btgysf9ma9bb6 + + CFBundleTypeRole + Editor + CFBundleURLName + Delta + CFBundleURLSchemes + + delta + + CFBundleVersion 10 diff --git a/Resources/Assets.xcassets/Link.imageset/Contents.json b/Resources/Assets.xcassets/Link.imageset/Contents.json new file mode 100644 index 0000000..0668ba2 --- /dev/null +++ b/Resources/Assets.xcassets/Link.imageset/Contents.json @@ -0,0 +1,26 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "Link@1x.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "Link@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "Link@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + }, + "properties" : { + "template-rendering-intent" : "template" + } +} \ No newline at end of file diff --git a/Resources/Assets.xcassets/Link.imageset/Link@1x.png b/Resources/Assets.xcassets/Link.imageset/Link@1x.png new file mode 100644 index 0000000..524f73c Binary files /dev/null and b/Resources/Assets.xcassets/Link.imageset/Link@1x.png differ diff --git a/Resources/Assets.xcassets/Link.imageset/Link@2x.png b/Resources/Assets.xcassets/Link.imageset/Link@2x.png new file mode 100644 index 0000000..50fd1b5 Binary files /dev/null and b/Resources/Assets.xcassets/Link.imageset/Link@2x.png differ diff --git a/Resources/Assets.xcassets/Link.imageset/Link@3x.png b/Resources/Assets.xcassets/Link.imageset/Link@3x.png new file mode 100644 index 0000000..c9e2f47 Binary files /dev/null and b/Resources/Assets.xcassets/Link.imageset/Link@3x.png differ