7
7
8
8
#if RCT_DEV && !TARGET_OS_UIKITFORMAC
9
9
10
- #import < UIKit/UIKit.h>
11
10
#import < React/RCTLog.h>
11
+ #import < UIKit/UIKit.h>
12
12
13
13
#import < React/RCTDefines.h>
14
14
#import < React/RCTInspectorPackagerConnection.h>
37
37
if (inspectorProxyPortStr && [inspectorProxyPortStr length ] > 0 ) {
38
38
inspectorProxyPort = [NSNumber numberWithInt: [inspectorProxyPortStr intValue ]];
39
39
}
40
- NSString *escapedDeviceName = [[[UIDevice currentDevice ] name ] stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet .URLQueryAllowedCharacterSet];
41
- NSString *escapedAppName = [[[NSBundle mainBundle ] bundleIdentifier ] stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet .URLQueryAllowedCharacterSet];
40
+ NSString *escapedDeviceName = [[[UIDevice currentDevice ] name ]
41
+ stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet .URLQueryAllowedCharacterSet];
42
+ NSString *escapedAppName = [[[NSBundle mainBundle ] bundleIdentifier ]
43
+ stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet .URLQueryAllowedCharacterSet];
42
44
return [NSURL URLWithString: [NSString stringWithFormat: @" http://%@ /inspector/device?name=%@ &app=%@ " ,
43
- getServerHost (bundleURL, inspectorProxyPort),
44
- escapedDeviceName,
45
- escapedAppName]];
45
+ getServerHost (bundleURL, inspectorProxyPort),
46
+ escapedDeviceName,
47
+ escapedAppName]];
46
48
}
47
49
48
50
static NSURL *getAttachDeviceUrl (NSURL *bundleURL, NSString *title)
52
54
if (metroBundlerPortStr && [metroBundlerPortStr length ] > 0 ) {
53
55
metroBundlerPort = [NSNumber numberWithInt: [metroBundlerPortStr intValue ]];
54
56
}
55
- NSString *escapedDeviceName = [[[UIDevice currentDevice ] name ] stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet .URLHostAllowedCharacterSet];
56
- NSString *escapedAppName = [[[NSBundle mainBundle ] bundleIdentifier ] stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet .URLHostAllowedCharacterSet];
57
+ NSString *escapedDeviceName = [[[UIDevice currentDevice ] name ]
58
+ stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet .URLHostAllowedCharacterSet];
59
+ NSString *escapedAppName = [[[NSBundle mainBundle ] bundleIdentifier ]
60
+ stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet .URLHostAllowedCharacterSet];
57
61
return [NSURL URLWithString: [NSString stringWithFormat: @" http://%@ /attach-debugger-nuclide?title=%@ &device=%@ &app=%@ " ,
58
- getServerHost (bundleURL, metroBundlerPort),
59
- title,
60
- escapedDeviceName,
61
- escapedAppName]];
62
+ getServerHost (bundleURL, metroBundlerPort),
63
+ title,
64
+ escapedDeviceName,
65
+ escapedAppName]];
62
66
}
63
67
64
68
@implementation RCTInspectorDevServerHelper
65
69
66
- RCT_NOT_IMPLEMENTED (- (instancetype )init)
70
+ RCT_NOT_IMPLEMENTED (-(instancetype )init)
67
71
68
72
static NSMutableDictionary<NSString *, RCTInspectorPackagerConnection *> *socketConnections = nil;
69
73
@@ -74,39 +78,34 @@ static void sendEventToAllConnections(NSString *event)
74
78
}
75
79
}
76
80
77
- static void displayErrorAlert (UIViewController *view, NSString *message) {
78
- UIAlertController *alert =
79
- [UIAlertController alertControllerWithTitle: nil
80
- message: message
81
- preferredStyle: UIAlertControllerStyleAlert];
81
+ static void displayErrorAlert (UIViewController *view, NSString *message)
82
+ {
83
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle: nil
84
+ message: message
85
+ preferredStyle: UIAlertControllerStyleAlert];
82
86
[view presentViewController: alert animated: YES completion: nil ];
83
- dispatch_after (
84
- dispatch_time (DISPATCH_TIME_NOW, NSEC_PER_SEC * 2.5 ),
85
- dispatch_get_main_queue (),
86
- ^{
87
- [alert dismissViewControllerAnimated: YES completion: nil ];
88
- });
87
+ dispatch_after (dispatch_time (DISPATCH_TIME_NOW, NSEC_PER_SEC * 2.5 ), dispatch_get_main_queue (), ^{
88
+ [alert dismissViewControllerAnimated: YES completion: nil ];
89
+ });
89
90
}
90
91
91
- + (void )attachDebugger : (NSString *)owner
92
- withBundleURL : (NSURL *)bundleURL
93
- withView : (UIViewController *)view
92
+ + (void )attachDebugger : (NSString *)owner withBundleURL : (NSURL *)bundleURL withView : (UIViewController *)view
94
93
{
95
94
NSURL *url = getAttachDeviceUrl (bundleURL, owner);
96
95
97
96
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url];
98
97
[request setHTTPMethod: @" GET" ];
99
98
100
99
__weak UIViewController *viewCapture = view;
101
- [[[NSURLSession sharedSession ] dataTaskWithRequest: request completionHandler:
102
- ^(__unused NSData *_Nullable data,
103
- __unused NSURLResponse *_Nullable response,
104
- NSError *_Nullable error) {
105
- UIViewController *viewCaptureStrong = viewCapture;
106
- if (error != nullptr && viewCaptureStrong != nullptr ) {
107
- displayErrorAlert (viewCaptureStrong, @" The request to attach Nuclide couldn't reach Metro Bundler !" );
108
- }
109
- }] resume ];
100
+ [[[NSURLSession sharedSession ]
101
+ dataTaskWithRequest: request
102
+ completionHandler: ^(
103
+ __unused NSData *_Nullable data, __unused NSURLResponse *_Nullable response, NSError *_Nullable error) {
104
+ UIViewController *viewCaptureStrong = viewCapture;
105
+ if (error != nullptr && viewCaptureStrong != nullptr ) {
106
+ displayErrorAlert (viewCaptureStrong, @" The request to attach Nuclide couldn't reach Metro!" );
107
+ }
108
+ }] resume ];
110
109
}
111
110
112
111
+ (void )disableDebugger
0 commit comments