Skip to content

Commit 217c54d

Browse files
authored
Merge pull request #19603 from wordpress-mobile/task/jetpack-overlay-universal-linking
Add universal link action for the Jetpack overlay
2 parents c7cd73f + 926c91b commit 217c54d

File tree

10 files changed

+82
-7
lines changed

10 files changed

+82
-7
lines changed

WordPress/Classes/System/WordPressAppDelegate.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,14 @@ extension WordPressAppDelegate {
504504
}
505505

506506
func handleWebActivity(_ activity: NSUserActivity) {
507+
// try to handle unauthenticated routes first.
508+
if activity.activityType == NSUserActivityTypeBrowsingWeb,
509+
let url = activity.webpageURL,
510+
UniversalLinkRouter.unauthenticated.canHandle(url: url) {
511+
UniversalLinkRouter.unauthenticated.handle(url: url)
512+
return
513+
}
514+
507515
guard AccountHelper.isLoggedIn,
508516
activity.activityType == NSUserActivityTypeBrowsingWeb,
509517
let url = activity.webpageURL else {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct JetpackRoute: Route {
2+
let path = "/app"
3+
let section: DeepLinkSection? = nil
4+
var action: NavigationAction {
5+
return self
6+
}
7+
}
8+
9+
extension JetpackRoute: NavigationAction {
10+
func perform(_ values: [String: String], source: UIViewController?, router: LinkRouter) {
11+
// We don't care where it opens in the app as long as it opens the app.
12+
// If we handle deferred linking only then it would be relevant.
13+
}
14+
}

WordPress/Classes/Utility/Universal Links/UniversalLinkRouter.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ struct UniversalLinkRouter: LinkRouter {
2525
static let shared = UniversalLinkRouter(
2626
routes: defaultRoutes)
2727

28+
// A singleton that handles universal link routes without requiring authentication.
29+
//
30+
static let unauthenticated = UniversalLinkRouter(routes: jetpackRoutes)
31+
2832
static let defaultRoutes: [Route] =
2933
redirects +
3034
meRoutes +
3135
newPostRoutes +
3236
newPageRoutes +
37+
jetpackRoutes +
3338
notificationsRoutes +
3439
readerRoutes +
3540
statsRoutes +
@@ -43,6 +48,10 @@ struct UniversalLinkRouter: LinkRouter {
4348
MeNotificationSettingsRoute()
4449
]
4550

51+
static let jetpackRoutes: [Route] = [
52+
JetpackRoute()
53+
]
54+
4655
static let newPostRoutes: [Route] = [
4756
NewPostRoute(),
4857
NewPostForSiteRoute()
@@ -120,8 +129,10 @@ struct UniversalLinkRouter: LinkRouter {
120129
return matcherCanHandle
121130
}
122131

123-
// If there's a hostname, check it's WordPress.com
124-
return scheme == "https" && host == "wordpress.com" && matcherCanHandle
132+
// If there's a hostname, check if it's WordPress.com or jetpack.com/app.
133+
return scheme == "https"
134+
&& (host == "wordpress.com" || host == "jetpack.com")
135+
&& matcherCanHandle
125136
}
126137

127138
/// Attempts to find a route that matches the url's path, and perform its

WordPress/Classes/ViewRelated/Jetpack/Branding/Coordinator/JetpackBrandingCoordinator.swift

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,37 @@ import UIKit
33
/// A class containing convenience methods for the the Jetpack branding experience
44
class JetpackBrandingCoordinator {
55

6+
/// Used to "guess" if the Jetpack app is already installed.
7+
/// The check is done from the WordPress side.
8+
///
9+
/// Note: The string values should kept in-sync with Jetpack's URL scheme.
10+
///
11+
static var jetpackDeepLinkScheme: String {
12+
#if DEBUG
13+
return "jpdebug"
14+
#elseif INTERNAL_BUILD
15+
return "jpinternal"
16+
#elseif ALPHA_BUILD
17+
return "jpalpha"
18+
#else
19+
return "jetpack"
20+
#endif
21+
}
22+
623
static func presentOverlay(from viewController: UIViewController, redirectAction: (() -> Void)? = nil) {
724

825
let action = redirectAction ?? {
9-
// TODO: Add here the default action to redirect to the jp app
26+
guard let jetpackDeepLinkURL = URL(string: "\(jetpackDeepLinkScheme)://app"),
27+
let jetpackUniversalLinkURL = URL(string: "https://jetpack.com/app"),
28+
let jetpackAppStoreURL = URL(string: "https://apps.apple.com/app/jetpack-website-builder/id1565481562") else {
29+
return
30+
}
31+
32+
// First, check if the WordPress app can open Jetpack by testing its URL scheme.
33+
// if we can potentially open Jetpack app, let's open it through universal link to avoid scheme conflicts (e.g., a certain game :-).
34+
// finally, if the user might not have Jetpack installed, direct them to App Store page.
35+
let urlToOpen = UIApplication.shared.canOpenURL(jetpackDeepLinkURL) ? jetpackUniversalLinkURL : jetpackAppStoreURL
36+
UIApplication.shared.open(urlToOpen)
1037
}
1138

1239
let jetpackOverlayViewController = JetpackOverlayViewController(viewFactory: makeJetpackOverlayView, redirectAction: action)

WordPress/Info.plist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@
496496
<false/>
497497
<key>LSApplicationQueriesSchemes</key>
498498
<array>
499+
<string>$(JP_SCHEME)</string>
499500
<string>org-appextension-feature-password-management</string>
500501
<string>twitter</string>
501502
<string>whatsapp</string>

WordPress/Jetpack/JetpackDebug.entitlements

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</array>
1111
<key>com.apple.developer.associated-domains</key>
1212
<array>
13+
<string>applinks:jetpack.com</string>
1314
<string>webcredentials:wordpress.com</string>
1415
<string>applinks:apps.wordpress.com</string>
1516
<string>applinks:wordpress.com</string>

WordPress/Jetpack/JetpackRelease-Alpha.entitlements

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<string>development</string>
77
<key>com.apple.developer.associated-domains</key>
88
<array>
9+
<string>applinks:jetpack.com</string>
910
<string>webcredentials:wordpress.com</string>
1011
<string>applinks:apps.wordpress.com</string>
1112
<string>applinks:wordpress.com</string>

WordPress/Jetpack/JetpackRelease-Internal.entitlements

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<string>development</string>
77
<key>com.apple.developer.associated-domains</key>
88
<array>
9+
<string>applinks:jetpack.com</string>
910
<string>webcredentials:wordpress.com</string>
1011
<string>applinks:apps.wordpress.com</string>
1112
<string>applinks:wordpress.com</string>

WordPress/Jetpack/JetpackRelease.entitlements

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</array>
1111
<key>com.apple.developer.associated-domains</key>
1212
<array>
13+
<string>applinks:jetpack.com</string>
1314
<string>webcredentials:wordpress.com</string>
1415
<string>applinks:apps.wordpress.com</string>
1516
<string>applinks:wordpress.com</string>

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@
186186
08216FD51CDBF96000304BA7 /* MenuItemTypeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 08216FC71CDBF96000304BA7 /* MenuItemTypeViewController.m */; };
187187
082635BB1CEA69280088030C /* MenuItemsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 082635BA1CEA69280088030C /* MenuItemsViewController.m */; };
188188
0828D7FA1E6E09AE00C7C7D4 /* WPAppAnalytics+Media.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0828D7F91E6E09AE00C7C7D4 /* WPAppAnalytics+Media.swift */; };
189+
082A645B291C2DD700668D2C /* Routes+Jetpack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 082A645A291C2DD700668D2C /* Routes+Jetpack.swift */; };
190+
082A645C291C2DD700668D2C /* Routes+Jetpack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 082A645A291C2DD700668D2C /* Routes+Jetpack.swift */; };
189191
082AB9D91C4EEEF4000CA523 /* PostTagService.m in Sources */ = {isa = PBXBuildFile; fileRef = 082AB9D81C4EEEF4000CA523 /* PostTagService.m */; };
190192
082AB9DD1C4F035E000CA523 /* PostTag.m in Sources */ = {isa = PBXBuildFile; fileRef = 082AB9DC1C4F035E000CA523 /* PostTag.m */; };
191193
0845B8C61E833C56001BA771 /* URL+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0845B8C51E833C56001BA771 /* URL+Helpers.swift */; };
@@ -5508,6 +5510,7 @@
55085510
082635B91CEA69280088030C /* MenuItemsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuItemsViewController.h; sourceTree = "<group>"; };
55095511
082635BA1CEA69280088030C /* MenuItemsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MenuItemsViewController.m; sourceTree = "<group>"; };
55105512
0828D7F91E6E09AE00C7C7D4 /* WPAppAnalytics+Media.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WPAppAnalytics+Media.swift"; sourceTree = "<group>"; };
5513+
082A645A291C2DD700668D2C /* Routes+Jetpack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Routes+Jetpack.swift"; sourceTree = "<group>"; };
55115514
082AB9D71C4EEEF4000CA523 /* PostTagService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PostTagService.h; sourceTree = "<group>"; };
55125515
082AB9D81C4EEEF4000CA523 /* PostTagService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PostTagService.m; sourceTree = "<group>"; };
55135516
082AB9DB1C4F035E000CA523 /* PostTag.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PostTag.h; sourceTree = "<group>"; };
@@ -9691,19 +9694,20 @@
96919694
1797373920EBDA1100377B4E /* Universal Links */ = {
96929695
isa = PBXGroup;
96939696
children = (
9697+
17BD4A182101D31B00975AC3 /* NavigationActionHelpers.swift */,
96949698
17B7C89F20EC1D6A0042E260 /* Route.swift */,
9699+
F574416C2425697D00E150A8 /* Route+Page.swift */,
9700+
1714F8CF20E6DA8900226DCB /* RouteMatcher.swift */,
96959701
17BD4A0720F76A4700975AC3 /* Routes+Banners.swift */,
9696-
174C11922624C78900346EC6 /* Routes+Start.swift */,
9702+
082A645A291C2DD700668D2C /* Routes+Jetpack.swift */,
96979703
F1655B4722A6C2FA00227BFB /* Routes+Mbar.swift */,
96989704
17F0E1D920EBDC0A001E9514 /* Routes+Me.swift */,
96999705
17E24F5320FCF1D900BD70A3 /* Routes+MySites.swift */,
97009706
17B7C8C020EE2A870042E260 /* Routes+Notifications.swift */,
97019707
1703D04B20ECD93800D292E9 /* Routes+Post.swift */,
9702-
F574416C2425697D00E150A8 /* Route+Page.swift */,
97039708
17A4A36820EE51870071C2CA /* Routes+Reader.swift */,
9709+
174C11922624C78900346EC6 /* Routes+Start.swift */,
97049710
1715179120F4B2EB002C4A38 /* Routes+Stats.swift */,
9705-
17BD4A182101D31B00975AC3 /* NavigationActionHelpers.swift */,
9706-
1714F8CF20E6DA8900226DCB /* RouteMatcher.swift */,
97079711
17B7C89D20EC1D0D0042E260 /* UniversalLinkRouter.swift */,
97089712
);
97099713
path = "Universal Links";
@@ -20804,6 +20808,7 @@
2080420808
D858F30120E20106007E8A1C /* LikePost.swift in Sources */,
2080520809
1703D04C20ECD93800D292E9 /* Routes+Post.swift in Sources */,
2080620810
E11C4B702010930B00A6619C /* Blog+Jetpack.swift in Sources */,
20811+
082A645B291C2DD700668D2C /* Routes+Jetpack.swift in Sources */,
2080720812
DC3B9B2C27739760003F7249 /* TimeZoneSelectorViewModel.swift in Sources */,
2080820813
F1DB8D292288C14400906E2F /* Uploader.swift in Sources */,
2080920814
3FB1929026C6109F000F5AA3 /* TimeSelectionView.swift in Sources */,
@@ -23179,6 +23184,7 @@
2317923184
FABB23312602FC2C00C8785C /* SettingsCommon.swift in Sources */,
2318023185
17C1D6922670E4A2006C8970 /* UIFont+Fitting.swift in Sources */,
2318123186
FABB23322602FC2C00C8785C /* FormatBarItemProviders.swift in Sources */,
23187+
082A645C291C2DD700668D2C /* Routes+Jetpack.swift in Sources */,
2318223188
FABB23332602FC2C00C8785C /* RevisionDiffViewController.swift in Sources */,
2318323189
FABB23342602FC2C00C8785C /* BlogDetailsSectionFooterView.swift in Sources */,
2318423190
3F435221289B2B5100CE19ED /* JetpackOverlayViewController.swift in Sources */,
@@ -24925,6 +24931,7 @@
2492524931
);
2492624932
INFOPLIST_FILE = Info.plist;
2492724933
INFOPLIST_PREPROCESS = YES;
24934+
JP_SCHEME = jpdebug;
2492824935
LD_RUNPATH_SEARCH_PATHS = (
2492924936
"$(inherited)",
2493024937
"@executable_path/Frameworks",
@@ -24991,6 +24998,7 @@
2499124998
);
2499224999
INFOPLIST_FILE = Info.plist;
2499325000
INFOPLIST_PREPROCESS = YES;
25001+
JP_SCHEME = jetpack;
2499425002
LD_RUNPATH_SEARCH_PATHS = (
2499525003
"$(inherited)",
2499625004
"@executable_path/Frameworks",
@@ -26992,6 +27000,7 @@
2699227000
);
2699327001
INFOPLIST_FILE = "WordPress-Alpha-Info.plist";
2699427002
INFOPLIST_PREPROCESS = YES;
27003+
JP_SCHEME = jpalpha;
2699527004
LD_RUNPATH_SEARCH_PATHS = (
2699627005
"$(inherited)",
2699727006
"@executable_path/Frameworks",
@@ -27429,6 +27438,7 @@
2742927438
);
2743027439
INFOPLIST_FILE = "WordPress-Internal-Info.plist";
2743127440
INFOPLIST_PREPROCESS = YES;
27441+
JP_SCHEME = jpinternal;
2743227442
LD_RUNPATH_SEARCH_PATHS = (
2743327443
"$(inherited)",
2743427444
"@executable_path/Frameworks",

0 commit comments

Comments
 (0)