Skip to content

Commit a840e90

Browse files
committed
Add UIApplication shortcuts
1 parent 2f952c3 commit a840e90

File tree

7 files changed

+124
-19
lines changed

7 files changed

+124
-19
lines changed

Classes/ObjectExplorers/FLEXObjectExplorerFactory.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import "FLEXClassShortcuts.h"
1212
#import "FLEXViewShortcuts.h"
1313
#import "FLEXViewControllerShortcuts.h"
14+
#import "FLEXUIAppShortcuts.h"
1415
#import "FLEXImageShortcuts.h"
1516
#import "FLEXLayerShortcuts.h"
1617
#import "FLEXColorPreviewSection.h"
@@ -35,6 +36,7 @@ + (void)initialize {
3536
ClassKey(NSOrderedSet) : [FLEXCollectionContentSection class],
3637
ClassKey(NSUserDefaults) : [FLEXDefaultsContentSection class],
3738
ClassKey(UIViewController) : [FLEXViewControllerShortcuts class],
39+
ClassKey(UIApplication) : [FLEXUIAppShortcuts class],
3840
ClassKey(UIView) : [FLEXViewShortcuts class],
3941
ClassKey(UIImage) : [FLEXImageShortcuts class],
4042
ClassKey(CALayer) : [FLEXLayerShortcuts class],

Classes/ObjectExplorers/Sections/Shortcuts/FLEXShortcutsFactory+Defaults.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#import "FLEXShortcutsSection.h"
1010

11+
@interface FLEXShortcutsFactory (UIApplication) @end
12+
1113
@interface FLEXShortcutsFactory (Views) @end
1214

1315
@interface FLEXShortcutsFactory (ViewControllers) @end

Classes/ObjectExplorers/Sections/Shortcuts/FLEXShortcutsFactory+Defaults.m

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@
1111
#import "FLEXRuntimeUtility.h"
1212
#import "NSObject+FLEX_Reflection.h"
1313

14+
#pragma mark - UIApplication
15+
16+
@implementation FLEXShortcutsFactory (UIApplication)
17+
18+
+ (void)load { FLEX_EXIT_IF_TESTING()
19+
self.append.classProperties(@[@"sharedApplication"]).forClass(UIApplication.flex_metaclass);
20+
self.append.properties(@[
21+
@"delegate", @"keyWindow", @"windows"
22+
]).forClass(UIApplication.class);
23+
24+
if (@available(iOS 13, *)) {
25+
self.append.properties(@[
26+
@"connectedScenes", @"openSessions", @"supportsMultipleScenes"
27+
]).forClass(UIApplication.class);
28+
}
29+
}
30+
31+
@end
32+
1433
#pragma mark - Views
1534

1635
@implementation FLEXShortcutsFactory (Views)
@@ -135,7 +154,7 @@ + (void)load { FLEX_EXIT_IF_TESTING()
135154
]).forClass(UIImage.class);
136155

137156
if (@available(iOS 13, *)) {
138-
self.append.properties(@[@"symbolImage"]);
157+
self.append.properties(@[@"symbolImage"]).forClass(UIImage.class);
139158
}
140159
}
141160

@@ -237,24 +256,6 @@ + (void)load { FLEX_EXIT_IF_TESTING()
237256
self.append.classProperties(@[
238257
@"defaultTimeZone", @"systemTimeZone", @"localTimeZone"
239258
]).forClass(NSTimeZone.class);
240-
241-
242-
// self.append.<#type#>(@[@"<#value#>"]).forClass(NSURLSession.class);
243-
//
244-
//
245-
// self.append.<#type#>(@[@"<#value#>"]).forClass(NSURLSession.class);
246-
//
247-
//
248-
// self.append.<#type#>(@[@"<#value#>"]).forClass(NSURLSession.class);
249-
//
250-
//
251-
// self.append.<#type#>(@[@"<#value#>"]).forClass(NSURLSession.class);
252-
//
253-
//
254-
// self.append.<#type#>(@[@"<#value#>"]).forClass(NSURLSession.class);
255-
//
256-
//
257-
// self.append.<#type#>(@[@"<#value#>"]).forClass(NSURLSession.class);
258259
}
259260

260261
@end

Classes/ObjectExplorers/Sections/Shortcuts/FLEXShortcutsSection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
/// Subclasses \e may override this to hide the disclosure indicator
6060
/// for some rows. It is shown for all rows by default, unless
6161
/// you initialize it with \c forObject:rowTitles:rowSubtitles:
62+
///
63+
/// When you hide the disclosure indicator, the row is not selectable.
6264
- (UITableViewCellAccessoryType)accessoryTypeForRow:(NSInteger)row;
6365

6466
/// The number of lines for the title and subtitle labels. Defaults to 1.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// FLEXUIAppShortcuts.h
3+
// FLEX
4+
//
5+
// Created by Tanner on 5/25/20.
6+
// Copyright © 2020 Flipboard. All rights reserved.
7+
//
8+
9+
#import "FLEXShortcutsSection.h"
10+
11+
@interface FLEXUIAppShortcuts : FLEXShortcutsSection
12+
13+
@end
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// FLEXUIAppShortcuts.m
3+
// FLEX
4+
//
5+
// Created by Tanner on 5/25/20.
6+
// Copyright © 2020 Flipboard. All rights reserved.
7+
//
8+
9+
#import "FLEXUIAppShortcuts.h"
10+
#import "FLEXRuntimeUtility.h"
11+
#import "FLEXShortcut.h"
12+
#import "FLEXAlert.h"
13+
14+
@implementation FLEXUIAppShortcuts
15+
16+
#pragma mark - Overrides
17+
18+
+ (instancetype)forObject:(UIApplication *)application {
19+
return [self forObject:application additionalRows:@[
20+
[FLEXActionShortcut title:@"Open URL…"
21+
subtitle:^NSString *(UIViewController *controller) {
22+
return nil;
23+
}
24+
selectionHandler:^void(UIViewController *host, UIApplication *app) {
25+
[FLEXAlert makeAlert:^(FLEXAlert *make) {
26+
make.title(@"Open URL");
27+
make.message(
28+
@"This will call openURL: or openURL:options:completion: "
29+
"with the string below. 'Open if Universal' will only open "
30+
"the URL if it is a registered Universal Link."
31+
);
32+
33+
make.textField(@"twitter://user?id=12345");
34+
make.button(@"Open").handler(^(NSArray<NSString *> *strings) {
35+
[self openURL:strings[0] inApp:app onlyIfUniveral:NO host:host];
36+
});
37+
make.button(@"Open if Universal").handler(^(NSArray<NSString *> *strings) {
38+
[self openURL:strings[0] inApp:app onlyIfUniveral:YES host:host];
39+
});
40+
make.button(@"Cancel").cancelStyle();
41+
} showFrom:host];
42+
}
43+
accessoryType:^UITableViewCellAccessoryType(UIViewController *controller) {
44+
return UITableViewCellAccessoryDisclosureIndicator;
45+
}
46+
]
47+
]];
48+
}
49+
50+
+ (void)openURL:(NSString *)urlString
51+
inApp:(UIApplication *)app
52+
onlyIfUniveral:(BOOL)universalOnly
53+
host:(UIViewController *)host {
54+
NSURL *url = [NSURL URLWithString:urlString];
55+
56+
if (url) {
57+
if (@available(iOS 10, *)) {
58+
[app openURL:url options:@{
59+
UIApplicationOpenURLOptionUniversalLinksOnly: @(universalOnly)
60+
} completionHandler:^(BOOL success) {
61+
if (!success) {
62+
[FLEXAlert showAlert:@"No Universal Link Handler"
63+
message:@"No installed application is registered to handle this link."
64+
from:host
65+
];
66+
}
67+
}];
68+
} else {
69+
[app openURL:url];
70+
}
71+
} else {
72+
[FLEXAlert showAlert:@"Error" message:@"Invalid URL" from:host];
73+
}
74+
}
75+
76+
@end
77+

FLEX.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@
164164
C32A195F231732E800EB02AC /* FLEXCollectionContentSection.m in Sources */ = {isa = PBXBuildFile; fileRef = C32A195D231732E800EB02AC /* FLEXCollectionContentSection.m */; };
165165
C32A19622317378C00EB02AC /* FLEXDefaultsContentSection.h in Headers */ = {isa = PBXBuildFile; fileRef = C32A19602317378C00EB02AC /* FLEXDefaultsContentSection.h */; settings = {ATTRIBUTES = (Public, ); }; };
166166
C32A19632317378C00EB02AC /* FLEXDefaultsContentSection.m in Sources */ = {isa = PBXBuildFile; fileRef = C32A19612317378C00EB02AC /* FLEXDefaultsContentSection.m */; };
167+
C32F3A18247C6B3E0063542D /* FLEXUIAppShortcuts.h in Headers */ = {isa = PBXBuildFile; fileRef = C32F3A16247C6B3E0063542D /* FLEXUIAppShortcuts.h */; };
168+
C32F3A19247C6B3E0063542D /* FLEXUIAppShortcuts.m in Sources */ = {isa = PBXBuildFile; fileRef = C32F3A17247C6B3E0063542D /* FLEXUIAppShortcuts.m */; };
167169
C33C825B23159EAF00DD2451 /* FLEXTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C33C825A23159EAF00DD2451 /* FLEXTests.m */; };
168170
C33C825E2316DC8600DD2451 /* FLEXObjectExplorer.h in Headers */ = {isa = PBXBuildFile; fileRef = C33C825C2316DC8600DD2451 /* FLEXObjectExplorer.h */; settings = {ATTRIBUTES = (Public, ); }; };
169171
C33C825F2316DC8600DD2451 /* FLEXObjectExplorer.m in Sources */ = {isa = PBXBuildFile; fileRef = C33C825D2316DC8600DD2451 /* FLEXObjectExplorer.m */; };
@@ -523,6 +525,8 @@
523525
C32A195D231732E800EB02AC /* FLEXCollectionContentSection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEXCollectionContentSection.m; sourceTree = "<group>"; };
524526
C32A19602317378C00EB02AC /* FLEXDefaultsContentSection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEXDefaultsContentSection.h; sourceTree = "<group>"; };
525527
C32A19612317378C00EB02AC /* FLEXDefaultsContentSection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEXDefaultsContentSection.m; sourceTree = "<group>"; };
528+
C32F3A16247C6B3E0063542D /* FLEXUIAppShortcuts.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEXUIAppShortcuts.h; sourceTree = "<group>"; };
529+
C32F3A17247C6B3E0063542D /* FLEXUIAppShortcuts.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEXUIAppShortcuts.m; sourceTree = "<group>"; };
526530
C33C825A23159EAF00DD2451 /* FLEXTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEXTests.m; sourceTree = "<group>"; };
527531
C33C825C2316DC8600DD2451 /* FLEXObjectExplorer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FLEXObjectExplorer.h; path = Classes/ObjectExplorers/FLEXObjectExplorer.h; sourceTree = SOURCE_ROOT; };
528532
C33C825D2316DC8600DD2451 /* FLEXObjectExplorer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FLEXObjectExplorer.m; path = Classes/ObjectExplorers/FLEXObjectExplorer.m; sourceTree = SOURCE_ROOT; };
@@ -1363,6 +1367,8 @@
13631367
C34D4EB723A2B17900C1F903 /* FLEXBundleShortcuts.m */,
13641368
C38EF26123A2FCD20047A7EC /* FLEXViewControllerShortcuts.h */,
13651369
C38EF26023A2FCD20047A7EC /* FLEXViewControllerShortcuts.m */,
1370+
C32F3A16247C6B3E0063542D /* FLEXUIAppShortcuts.h */,
1371+
C32F3A17247C6B3E0063542D /* FLEXUIAppShortcuts.m */,
13661372
C31D93E223E38CBE005517BF /* FLEXBlockShortcuts.h */,
13671373
C31D93E323E38CBE005517BF /* FLEXBlockShortcuts.m */,
13681374
);
@@ -1489,6 +1495,7 @@
14891495
C3BFD070233C23ED0015FB82 /* NSArray+FLEX.h in Headers */,
14901496
C398682923AC370100E9E391 /* FLEXViewShortcuts.h in Headers */,
14911497
C3474C4023DA496400466532 /* FLEXKeyValueTableViewCell.h in Headers */,
1498+
C32F3A18247C6B3E0063542D /* FLEXUIAppShortcuts.h in Headers */,
14921499
779B1ED61C0C4D7C001F5E49 /* FLEXTableContentViewController.h in Headers */,
14931500
C3DFCDB82418336D00BB7084 /* NSUserDefaults+FLEX.h in Headers */,
14941501
3A4C95221B5B21410088C3F2 /* FLEXFileBrowserSearchOperation.h in Headers */,
@@ -1755,6 +1762,7 @@
17551762
3A4C94CE1B5B21410088C3F2 /* FLEXGlobalsEntry.m in Sources */,
17561763
C398625223AD6C67007E6793 /* FLEXKeyPathSearchController.m in Sources */,
17571764
C3E5D9FE2316E83700E655DB /* FLEXRuntime+Compare.m in Sources */,
1765+
C32F3A19247C6B3E0063542D /* FLEXUIAppShortcuts.m in Sources */,
17581766
71E1C2192307FBB800F5032A /* FLEXKeychainQuery.m in Sources */,
17591767
C398627323AD7951007E6793 /* UIGestureRecognizer+Blocks.m in Sources */,
17601768
C3F646F723A04A7500D4A011 /* FLEXShortcut.m in Sources */,

0 commit comments

Comments
 (0)