Skip to content

Commit 7650996

Browse files
committed
“Fix” Xcode 8 support
The user activity API has been ifdef out to fix Xcode 8 support.
1 parent ec23a6a commit 7650996

5 files changed

+45
-14
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ matrix:
55
include:
66
- language: objective-c
77
os: osx
8-
osx_image: xcode9
8+
osx_image: xcode9.2
99
env:
1010
- REACT_NATIVE_VERSION=0.53.3
1111
install:
@@ -14,7 +14,7 @@ matrix:
1414
- ./scripts/ci.ios.sh
1515
- language: objective-c
1616
os: osx
17-
osx_image: xcode9
17+
osx_image: xcode9.2
1818
env:
1919
- REACT_NATIVE_VERSION=0.49.3
2020
install:

detox/ios/Detox/DetoxAppDelegateProxy.h

+2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
@property (class, nonatomic, strong, readonly) DetoxAppDelegateProxy* currentAppDelegateProxy;
1515

16+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
1617
- (void)__dtx_dispatchUserActivityFromDataURL:(NSURL*)userActivityDataURL delayUntilActive:(BOOL)delay;
18+
#endif
1719
- (void)__dtx_dispatchUserNotificationFromDataURL:(NSURL*)userNotificationDataURL delayUntilActive:(BOOL)delay;
1820
- (void)__dtx_dispatchOpenURL:(NSURL*)URL options:(NSDictionary*)options delayUntilActive:(BOOL)delay;
1921

detox/ios/Detox/DetoxAppDelegateProxy.m

+35-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
static DetoxAppDelegateProxy* _currentAppDelegateProxy;
2020
static NSMutableArray<NSDictionary*>* _pendingOpenURLs;
2121
static NSMutableArray<DetoxUserNotificationDispatcher*>* _pendingUserNotificationDispatchers;
22+
static DetoxUserNotificationDispatcher* _pendingLaunchUserNotificationDispatcher;
23+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
2224
static NSMutableArray<DetoxUserActivityDispatcher*>* _pendingUserActivityDispatchers;
2325
static DetoxUserActivityDispatcher* _pendingLaunchUserActivityDispatcher;
24-
static DetoxUserNotificationDispatcher* _pendingLaunchUserNotificationDispatcher;
26+
#endif
2527

2628
static COSTouchVisualizerWindow* _touchVisualizerWindow;
2729

@@ -37,6 +39,7 @@
3739
return [NSURL fileURLWithPath:userNotificationDataPath];
3840
}
3941

42+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
4043
static NSURL* _launchUserActivityDataURL()
4144
{
4245
NSString* userActivityDataPath = [[NSUserDefaults standardUserDefaults] objectForKey:@"detoxUserActivityDataURL"];
@@ -48,6 +51,7 @@
4851

4952
return [NSURL fileURLWithPath:userActivityDataPath];
5053
}
54+
#endif
5155

5256
@interface UIWindow (DTXEventProxy) @end
5357

@@ -123,13 +127,18 @@ + (void)load
123127
dispatch_once(&onceToken, ^{
124128
_pendingOpenURLs = [NSMutableArray new];
125129
_pendingUserNotificationDispatchers = [NSMutableArray new];
130+
131+
NSURL* url;
132+
133+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
126134
_pendingUserActivityDispatchers = [NSMutableArray new];
127135

128-
NSURL* url = _launchUserActivityDataURL();
136+
url = _launchUserActivityDataURL();
129137
if(url)
130138
{
131139
_pendingLaunchUserActivityDispatcher = [[DetoxUserActivityDispatcher alloc] initWithUserActivityDataURL:url];
132140
}
141+
#endif
133142

134143
url = _launchUserNotificationDataURL();
135144
if(url)
@@ -188,7 +197,10 @@ - (NSString*)__dtx_sourceAppOverride
188197
return [[NSUserDefaults standardUserDefaults] objectForKey:@"detoxSourceAppOverride"];
189198
}
190199

191-
- (NSDictionary*)__dtx_prepareLaunchOptions:(NSDictionary*)launchOptions userNotificationDispatcher:(DetoxUserNotificationDispatcher*)notificationDispatcher userActivityDispatcher:(DetoxUserActivityDispatcher*)activityDispatcher
200+
- (NSDictionary*)__dtx_prepareLaunchOptions:(NSDictionary*)launchOptions userNotificationDispatcher:(DetoxUserNotificationDispatcher*)notificationDispatcher
201+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
202+
userActivityDispatcher:(DetoxUserActivityDispatcher*)activityDispatcher
203+
#endif
192204
{
193205
NSMutableDictionary* rv = [launchOptions mutableCopy] ?: [NSMutableDictionary new];
194206

@@ -197,6 +209,7 @@ - (NSDictionary*)__dtx_prepareLaunchOptions:(NSDictionary*)launchOptions userNot
197209
rv[UIApplicationLaunchOptionsRemoteNotificationKey] = [notificationDispatcher remoteNotification];
198210
}
199211

212+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
200213
if(activityDispatcher)
201214
{
202215
NSUserActivity* userActivity = [activityDispatcher userActivity];
@@ -208,7 +221,7 @@ - (NSDictionary*)__dtx_prepareLaunchOptions:(NSDictionary*)launchOptions userNot
208221

209222
rv[UIApplicationLaunchOptionsUserActivityDictionaryKey] = userActivityDictionary;
210223
}
211-
224+
#endif
212225

213226
NSURL* openURLOverride = [self __dtx_URLOverride];
214227
if(openURLOverride)
@@ -226,7 +239,11 @@ - (NSDictionary*)__dtx_prepareLaunchOptions:(NSDictionary*)launchOptions userNot
226239

227240
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey, id>*)launchOptions
228241
{
229-
launchOptions = [self __dtx_prepareLaunchOptions:launchOptions userNotificationDispatcher:_pendingLaunchUserNotificationDispatcher userActivityDispatcher:_pendingLaunchUserActivityDispatcher];
242+
launchOptions = [self __dtx_prepareLaunchOptions:launchOptions userNotificationDispatcher:_pendingLaunchUserNotificationDispatcher
243+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
244+
userActivityDispatcher:_pendingLaunchUserActivityDispatcher
245+
#endif
246+
];
230247

231248
BOOL rv = YES;
232249
if([class_getSuperclass(object_getClass(self)) instancesRespondToSelector:_cmd])
@@ -241,7 +258,11 @@ - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:
241258

242259
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions
243260
{
244-
launchOptions = [self __dtx_prepareLaunchOptions:launchOptions userNotificationDispatcher:_pendingLaunchUserNotificationDispatcher userActivityDispatcher:_pendingLaunchUserActivityDispatcher];
261+
launchOptions = [self __dtx_prepareLaunchOptions:launchOptions userNotificationDispatcher:_pendingLaunchUserNotificationDispatcher
262+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
263+
userActivityDispatcher:_pendingLaunchUserActivityDispatcher
264+
#endif
265+
];
245266

246267
BOOL rv = YES;
247268
if([class_getSuperclass(object_getClass(self)) instancesRespondToSelector:_cmd])
@@ -252,10 +273,14 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
252273
}
253274

254275
[_pendingLaunchUserNotificationDispatcher dispatchOnAppDelegate:self simulateDuringLaunch:YES];
276+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
255277
[_pendingLaunchUserActivityDispatcher dispatchOnAppDelegate:self];
278+
#endif
256279

257280
_pendingLaunchUserNotificationDispatcher = nil;
281+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
258282
_pendingLaunchUserActivityDispatcher = nil;
283+
#endif
259284

260285
if([self __dtx_URLOverride] && [class_getSuperclass(object_getClass(self)) instancesRespondToSelector:@selector(application:openURL:options:)])
261286
{
@@ -285,10 +310,12 @@ - (void)applicationWillEnterForeground:(UIApplication *)application
285310
}];
286311
[_pendingUserNotificationDispatchers removeAllObjects];
287312

313+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
288314
[_pendingUserActivityDispatchers enumerateObjectsUsingBlock:^(DetoxUserActivityDispatcher * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
289315
[self __dtx_actualDispatchUserActivityWithDispatcher:obj];
290316
}];
291317
[_pendingUserActivityDispatchers removeAllObjects];
318+
#endif
292319
});
293320
}
294321

@@ -297,6 +324,7 @@ - (BOOL)touchVisualizerWindowShouldAlwaysShowFingertip:(COSTouchVisualizerWindow
297324
return YES;
298325
}
299326

327+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
300328
- (void)__dtx_actualDispatchUserActivityWithDispatcher:(DetoxUserActivityDispatcher*)dispatcher
301329
{
302330
[dispatcher dispatchOnAppDelegate:self];
@@ -315,6 +343,7 @@ - (void)__dtx_dispatchUserActivityFromDataURL:(NSURL*)userActivityDataURL delayU
315343
[self __dtx_actualDispatchUserActivityWithDispatcher:dispatcher];
316344
}
317345
}
346+
#endif
318347

319348
- (void)__dtx_actualDispatchUserNotificationWithDispatcher:(DetoxUserNotificationDispatcher*)dispatcher
320349
{

detox/ios/Detox/DetoxManager.m

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ - (void)websocketDidReceiveAction:(NSString *)type withParams:(NSDictionary *)pa
176176
sendDoneAction(self.webSocket, messageId);
177177
};
178178
}
179+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_10_3
179180
else if(params[@"detoxUserActivityDataURL"])
180181
{
181182
NSURL* userActivityDataURL = [NSURL fileURLWithPath:params[@"detoxUserActivityDataURL"]];
@@ -188,6 +189,7 @@ - (void)websocketDidReceiveAction:(NSString *)type withParams:(NSDictionary *)pa
188189
sendDoneAction(self.webSocket, messageId);
189190
};
190191
}
192+
#endif
191193

192194
NSAssert(block != nil, @"Logic error, no block was generated for payload: %@", params);
193195

detox/ios/Detox/DetoxUserActivityDispatcher.swift

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// Copyright © 2018 Wix. All rights reserved.
77
//
88

9+
#if swift(>=3.2)
10+
911
import UIKit
1012

1113
private struct DetoxUserActivityKeys {
@@ -38,7 +40,7 @@ public class DetoxUserActivityDispatcher: NSObject {
3840
return jsonObject
3941
}
4042

41-
public lazy var userActivity: NSUserActivity = {
43+
@objc public lazy var userActivity: NSUserActivity = {
4244
guard let activityType = self.userActivityData[DetoxUserActivityKeys.activityType] as? String, activityType.count > 0 else {
4345
Swift.fatalError("Missing or invalid activity type")
4446
}
@@ -70,8 +72,4 @@ public class DetoxUserActivityDispatcher: NSObject {
7072
}
7173
}
7274

73-
//extension NSUserActivity {
74-
// @objc override open func setValue(_ value: Any?, forUndefinedKey key: String) {
75-
//
76-
// }
77-
//}
75+
#endif

0 commit comments

Comments
 (0)