@capacitor/ios 5.0.0-alpha.1 → 5.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -287,7 +287,6 @@ extension CAPBridgeViewController {
287
287
  aWebView.scrollView.bounces = false
288
288
  aWebView.scrollView.contentInsetAdjustmentBehavior = configuration.contentInsetAdjustmentBehavior
289
289
  aWebView.allowsLinkPreview = configuration.allowLinkPreviews
290
- aWebView.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")
291
290
  aWebView.scrollView.isScrollEnabled = configuration.scrollingEnabled
292
291
  if let overrideUserAgent = configuration.overridenUserAgentString {
293
292
  aWebView.customUserAgent = overrideUserAgent
@@ -12,6 +12,7 @@ extension CAPBridgedPlugin where Self: CAPPlugin {
12
12
  webView = bridge.webView
13
13
  shouldStringifyDatesInCalls = true
14
14
  retainedEventArguments = [:]
15
+ eventListeners = [:]
15
16
  pluginId = identifier
16
17
  pluginName = jsName
17
18
  load()
@@ -13,7 +13,7 @@
13
13
  @property (nonatomic, strong, nonnull) NSString *pluginId;
14
14
  @property (nonatomic, strong, nonnull) NSString *pluginName;
15
15
  @property (nonatomic, strong, nullable) NSMutableDictionary<NSString *, NSMutableArray<CAPPluginCall *>*> *eventListeners;
16
- @property (nonatomic, strong, nullable) NSMutableDictionary<NSString *, id> *retainedEventArguments;
16
+ @property (nonatomic, strong, nullable) NSMutableDictionary<NSString *, NSMutableArray<id> *> *retainedEventArguments;
17
17
  @property (nonatomic, assign) BOOL shouldStringifyDatesInCalls;
18
18
 
19
19
  - (instancetype _Nonnull) initWithBridge:(id<CAPBridgeProtocol> _Nonnull) bridge pluginId:(NSString* _Nonnull) pluginId pluginName:(NSString* _Nonnull) pluginName DEPRECATED_MSG_ATTRIBUTE("This initializer is deprecated and is not suggested for use. Any data set through this init method will be overridden when it is loaded on the bridge.");
@@ -52,13 +52,17 @@
52
52
  }
53
53
 
54
54
  - (void)sendRetainedArgumentsForEvent:(NSString *)eventName {
55
- id retained = [self.retainedEventArguments objectForKey:eventName];
56
- if (retained == nil) {
57
- return;
58
- }
59
-
60
- [self notifyListeners:eventName data:retained];
61
- [self.retainedEventArguments removeObjectForKey:eventName];
55
+ // copy retained args and null source to prevent potential race conditions
56
+ NSMutableArray *retained = [self.retainedEventArguments objectForKey:eventName];
57
+ if (retained == nil) {
58
+ return;
59
+ }
60
+
61
+ [self.retainedEventArguments removeObjectForKey:eventName];
62
+
63
+ for(id data in retained) {
64
+ [self notifyListeners:eventName data:data];
65
+ }
62
66
  }
63
67
 
64
68
  - (void)removeEventListener:(NSString *)eventName listener:(CAPPluginCall *)listener {
@@ -79,7 +83,12 @@
79
83
  NSArray<CAPPluginCall *> *listenersForEvent = [self.eventListeners objectForKey:eventName];
80
84
  if(listenersForEvent == nil || [listenersForEvent count] == 0) {
81
85
  if (retain == YES) {
82
- [self.retainedEventArguments setObject:data forKey:eventName];
86
+
87
+ if ([self.retainedEventArguments objectForKey:eventName] == nil) {
88
+ [self.retainedEventArguments setObject:[[NSMutableArray alloc] init] forKey:eventName];
89
+ }
90
+
91
+ [[self.retainedEventArguments objectForKey:eventName] addObject:data];
83
92
  }
84
93
  return;
85
94
  }
@@ -157,7 +157,6 @@ extension CAPWebView {
157
157
  webView.scrollView.bounces = false
158
158
  webView.scrollView.contentInsetAdjustmentBehavior = configuration.contentInsetAdjustmentBehavior
159
159
  webView.allowsLinkPreview = configuration.allowLinkPreviews
160
- webView.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")
161
160
  webView.scrollView.isScrollEnabled = configuration.scrollingEnabled
162
161
 
163
162
  if let overrideUserAgent = configuration.overridenUserAgentString {
@@ -31,7 +31,7 @@ public enum ResponseType: String {
31
31
  /// - Returns: The parsed value or an error
32
32
  func tryParseJson(_ data: Data) -> Any {
33
33
  do {
34
- return try JSONSerialization.jsonObject(with: data, options: .mutableContainers)
34
+ return try JSONSerialization.jsonObject(with: data, options: [.mutableContainers, .fragmentsAllowed])
35
35
  } catch {
36
36
  return error.localizedDescription
37
37
  }
@@ -384,9 +384,13 @@ var nativeBridge = (function (exports) {
384
384
  data: (options === null || options === void 0 ? void 0 : options.body) ? options.body : undefined,
385
385
  headers: headers,
386
386
  });
387
- const data = typeof nativeResponse.data === 'string'
387
+ let data = !nativeResponse.headers['Content-Type'].startsWith('application/json')
388
388
  ? nativeResponse.data
389
389
  : JSON.stringify(nativeResponse.data);
390
+ // use null data for 204 No Content HTTP response
391
+ if (nativeResponse.status === 204) {
392
+ data = null;
393
+ }
390
394
  // intercept & parse response before returning
391
395
  const response = new Response(data, {
392
396
  headers: nativeResponse.headers,
@@ -522,7 +526,7 @@ var nativeBridge = (function (exports) {
522
526
  this.status = nativeResponse.status;
523
527
  this.response = nativeResponse.data;
524
528
  this.responseText =
525
- typeof nativeResponse.data === 'string'
529
+ !nativeResponse.headers['Content-Type'].startsWith('application/json')
526
530
  ? nativeResponse.data
527
531
  : JSON.stringify(nativeResponse.data);
528
532
  this.responseURL = nativeResponse.url;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/ios",
3
- "version": "5.0.0-alpha.1",
3
+ "version": "5.0.0-beta.0",
4
4
  "description": "Capacitor: Cross-platform apps with JavaScript and the web",
5
5
  "homepage": "https://capacitorjs.com",
6
6
  "author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
@@ -25,10 +25,10 @@
25
25
  "xc:build:CapacitorCordova": "cd CapacitorCordova && xcodebuild && cd .."
26
26
  },
27
27
  "peerDependencies": {
28
- "@capacitor/core": "^5.0.0-alpha.0"
28
+ "@capacitor/core": "^5.0.0-alpha.1"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
- "gitHead": "76202ca81b8e855df0ef8e5f6a36bd65ed1469a4"
33
+ "gitHead": "51a548b97129998de8c403b2a8eb0421135af812"
34
34
  }