@capacitor-plus/ios 8.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.
- package/Capacitor/Capacitor/AppUUID.swift +51 -0
- package/Capacitor/Capacitor/Array+Capacitor.swift +31 -0
- package/Capacitor/Capacitor/CAPApplicationDelegateProxy.swift +32 -0
- package/Capacitor/Capacitor/CAPBridge.swift +25 -0
- package/Capacitor/Capacitor/CAPBridgeDelegate.swift +6 -0
- package/Capacitor/Capacitor/CAPBridgeProtocol.swift +148 -0
- package/Capacitor/Capacitor/CAPBridgeViewController+CDVScreenOrientationDelegate.h +6 -0
- package/Capacitor/Capacitor/CAPBridgeViewController+CDVScreenOrientationDelegate.m +5 -0
- package/Capacitor/Capacitor/CAPBridgeViewController.swift +384 -0
- package/Capacitor/Capacitor/CAPBridgedJSTypes.h +18 -0
- package/Capacitor/Capacitor/CAPBridgedJSTypes.m +43 -0
- package/Capacitor/Capacitor/CAPBridgedPlugin+getMethod.swift +13 -0
- package/Capacitor/Capacitor/CAPBridgedPlugin.h +41 -0
- package/Capacitor/Capacitor/CAPFile.swift +14 -0
- package/Capacitor/Capacitor/CAPInstanceConfiguration.h +38 -0
- package/Capacitor/Capacitor/CAPInstanceConfiguration.m +93 -0
- package/Capacitor/Capacitor/CAPInstanceConfiguration.swift +78 -0
- package/Capacitor/Capacitor/CAPInstanceDescriptor.h +167 -0
- package/Capacitor/Capacitor/CAPInstanceDescriptor.m +56 -0
- package/Capacitor/Capacitor/CAPInstanceDescriptor.swift +198 -0
- package/Capacitor/Capacitor/CAPInstancePlugin.swift +10 -0
- package/Capacitor/Capacitor/CAPLog.swift +11 -0
- package/Capacitor/Capacitor/CAPNotifications.swift +69 -0
- package/Capacitor/Capacitor/CAPPlugin+LoadInstance.swift +20 -0
- package/Capacitor/Capacitor/CAPPlugin.h +60 -0
- package/Capacitor/Capacitor/CAPPlugin.m +180 -0
- package/Capacitor/Capacitor/CAPPluginCall.h +25 -0
- package/Capacitor/Capacitor/CAPPluginCall.m +36 -0
- package/Capacitor/Capacitor/CAPPluginCall.swift +97 -0
- package/Capacitor/Capacitor/CAPPluginMethod.h +36 -0
- package/Capacitor/Capacitor/CAPPluginMethod.m +44 -0
- package/Capacitor/Capacitor/CAPPluginMethod.swift +17 -0
- package/Capacitor/Capacitor/Capacitor.h +15 -0
- package/Capacitor/Capacitor/Capacitor.modulemap +8 -0
- package/Capacitor/Capacitor/CapacitorBridge.swift +768 -0
- package/Capacitor/Capacitor/CapacitorExtension.swift +24 -0
- package/Capacitor/Capacitor/Codable/JSValueDecoder.swift +479 -0
- package/Capacitor/Capacitor/Codable/JSValueEncoder.swift +671 -0
- package/Capacitor/Capacitor/Data+Capacitor.swift +22 -0
- package/Capacitor/Capacitor/DocLinks.swift +8 -0
- package/Capacitor/Capacitor/Info.plist +24 -0
- package/Capacitor/Capacitor/JS.swift +122 -0
- package/Capacitor/Capacitor/JSExport.swift +218 -0
- package/Capacitor/Capacitor/JSTypes.swift +254 -0
- package/Capacitor/Capacitor/KeyPath.swift +60 -0
- package/Capacitor/Capacitor/KeyValueStore.swift +303 -0
- package/Capacitor/Capacitor/NotificationHandlerProtocol.swift +6 -0
- package/Capacitor/Capacitor/NotificationRouter.swift +60 -0
- package/Capacitor/Capacitor/PluginCallResult.swift +106 -0
- package/Capacitor/Capacitor/PluginConfig.swift +56 -0
- package/Capacitor/Capacitor/Plugins/CapacitorCookieManager.swift +141 -0
- package/Capacitor/Capacitor/Plugins/CapacitorCookies.swift +57 -0
- package/Capacitor/Capacitor/Plugins/CapacitorHttp.swift +57 -0
- package/Capacitor/Capacitor/Plugins/CapacitorUrlRequest.swift +225 -0
- package/Capacitor/Capacitor/Plugins/Console.swift +16 -0
- package/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift +236 -0
- package/Capacitor/Capacitor/Plugins/SystemBars.swift +133 -0
- package/Capacitor/Capacitor/Plugins/WebView.swift +44 -0
- package/Capacitor/Capacitor/PrivacyInfo.xcprivacy +14 -0
- package/Capacitor/Capacitor/Router.swift +29 -0
- package/Capacitor/Capacitor/TmpViewController.swift +8 -0
- package/Capacitor/Capacitor/UIColor.swift +55 -0
- package/Capacitor/Capacitor/UIStatusBarManager+CAPHandleTapAction.m +37 -0
- package/Capacitor/Capacitor/WKWebView+Capacitor.m +15 -0
- package/Capacitor/Capacitor/WKWebView+Capacitor.swift +80 -0
- package/Capacitor/Capacitor/WebViewAssetHandler.swift +550 -0
- package/Capacitor/Capacitor/WebViewDelegationHandler.swift +361 -0
- package/Capacitor/Capacitor/assets/native-bridge.js +1029 -0
- package/Capacitor.podspec +23 -0
- package/CapacitorCordova/CapacitorCordova/CapacitorCordova.h +25 -0
- package/CapacitorCordova/CapacitorCordova/CapacitorCordova.modulemap +6 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.h +8 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.m +5 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDV.h +28 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVAvailability.h +109 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVAvailabilityDeprecated.h +21 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegate.h +49 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.h +39 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.m +149 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.h +31 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.m +81 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.h +52 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.m +116 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin+Resources.h +39 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin+Resources.m +38 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.h +76 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.m +136 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.h +25 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.m +77 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.h +82 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.m +216 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVScreenOrientationDelegate.h +33 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.h +27 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.m +74 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.h +30 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.m +37 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVWebViewProcessPoolFactory.h +34 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVWebViewProcessPoolFactory.m +55 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.h +35 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.m +63 -0
- package/CapacitorCordova/CapacitorCordova/Info.plist +26 -0
- package/CapacitorCordova/CapacitorCordova/PrivacyInfo.xcprivacy +14 -0
- package/CapacitorCordova.podspec +26 -0
- package/LICENSE +21 -0
- package/package.json +33 -0
- package/scripts/pods_helpers.rb +12 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <WebKit/WebKit.h>
|
|
3
|
+
|
|
4
|
+
@protocol CAPBridgeProtocol;
|
|
5
|
+
@class CAPPluginCall;
|
|
6
|
+
|
|
7
|
+
@class PluginConfig;
|
|
8
|
+
|
|
9
|
+
@interface CAPPlugin : NSObject
|
|
10
|
+
|
|
11
|
+
@property (nonatomic, weak, nullable) WKWebView *webView;
|
|
12
|
+
@property (nonatomic, weak, nullable) id<CAPBridgeProtocol> bridge;
|
|
13
|
+
@property (nonatomic, strong, nonnull) NSString *pluginId;
|
|
14
|
+
@property (nonatomic, strong, nonnull) NSString *pluginName;
|
|
15
|
+
@property (nonatomic, strong, nullable) NSMutableDictionary<NSString *, NSMutableArray<CAPPluginCall *>*> *eventListeners;
|
|
16
|
+
@property (nonatomic, strong, nullable) NSMutableDictionary<NSString *, NSMutableArray<id> *> *retainedEventArguments;
|
|
17
|
+
@property (nonatomic, assign) BOOL shouldStringifyDatesInCalls;
|
|
18
|
+
|
|
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.");
|
|
20
|
+
- (void)addEventListener:(NSString* _Nonnull)eventName listener:(CAPPluginCall* _Nonnull)listener;
|
|
21
|
+
- (void)removeEventListener:(NSString* _Nonnull)eventName listener:(CAPPluginCall* _Nonnull)listener;
|
|
22
|
+
- (void)notifyListeners:(NSString* _Nonnull)eventName data:(NSDictionary<NSString *, id>* _Nullable)data;
|
|
23
|
+
- (void)notifyListeners:(NSString* _Nonnull)eventName data:(NSDictionary<NSString *, id>* _Nullable)data retainUntilConsumed:(BOOL)retain;
|
|
24
|
+
- (NSArray<CAPPluginCall *>* _Nullable)getListeners:(NSString* _Nonnull)eventName;
|
|
25
|
+
- (BOOL)hasListeners:(NSString* _Nonnull)eventName;
|
|
26
|
+
- (void)addListener:(CAPPluginCall* _Nonnull)call;
|
|
27
|
+
- (void)removeListener:(CAPPluginCall* _Nonnull)call;
|
|
28
|
+
- (void)removeAllListeners:(CAPPluginCall* _Nonnull)call;
|
|
29
|
+
/**
|
|
30
|
+
* Default implementation of the capacitor 3.0 permission pattern
|
|
31
|
+
*/
|
|
32
|
+
- (void)checkPermissions:(CAPPluginCall* _Nonnull)call;
|
|
33
|
+
- (void)requestPermissions:(CAPPluginCall* _Nonnull)call;
|
|
34
|
+
/**
|
|
35
|
+
* Give the plugins a chance to take control when a URL is about to be loaded in the WebView.
|
|
36
|
+
* Returning true causes the WebView to abort loading the URL.
|
|
37
|
+
* Returning false causes the WebView to continue loading the URL.
|
|
38
|
+
* Returning nil will defer to the default Capacitor policy
|
|
39
|
+
*/
|
|
40
|
+
- (NSNumber* _Nullable)shouldOverrideLoad:(WKNavigationAction* _Nonnull)navigationAction;
|
|
41
|
+
/**
|
|
42
|
+
* Allows plugins to hook into and respond to the WebView's URL authentication challenge.
|
|
43
|
+
* Returning false will defer to the default response of [.rejectProtectionSpace](https://developer.apple.com/documentation/Foundation/URLSession/AuthChallengeDisposition/rejectProtectionSpace).
|
|
44
|
+
*/
|
|
45
|
+
- (BOOL)handleWKWebViewURLAuthenticationChallenge:(NSURLAuthenticationChallenge* _Nonnull)challenge completionHandler:(void (^_Nonnull)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler;
|
|
46
|
+
|
|
47
|
+
// Called after init if the plugin wants to do
|
|
48
|
+
// some loading so the plugin author doesn't
|
|
49
|
+
// need to override init()
|
|
50
|
+
-(void)load;
|
|
51
|
+
-(NSString* _Nonnull)getId;
|
|
52
|
+
-(BOOL)getBool:(CAPPluginCall* _Nonnull) call field:(NSString* _Nonnull)field defaultValue:(BOOL)defaultValue DEPRECATED_MSG_ATTRIBUTE("Use accessors on CAPPluginCall instead. See CAPBridgedJSTypes.h for Obj-C implementations.");
|
|
53
|
+
-(NSString* _Nullable)getString:(CAPPluginCall* _Nonnull)call field:(NSString* _Nonnull)field defaultValue:(NSString* _Nonnull)defaultValue DEPRECATED_MSG_ATTRIBUTE("Use accessors on CAPPluginCall instead. See CAPBridgedJSTypes.h for Obj-C implementations.");
|
|
54
|
+
-(id _Nullable)getConfigValue:(NSString* _Nonnull)key __deprecated_msg("use getConfig() and access config values using the methods available depending on the type.");
|
|
55
|
+
-(PluginConfig* _Nonnull)getConfig;
|
|
56
|
+
-(void)setCenteredPopover:(UIViewController* _Nonnull) vc;
|
|
57
|
+
-(void)setCenteredPopover:(UIViewController* _Nonnull) vc size:(CGSize) size;
|
|
58
|
+
-(BOOL)supportsPopover DEPRECATED_MSG_ATTRIBUTE("All iOS 13+ devices support popover");
|
|
59
|
+
|
|
60
|
+
@end
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#import "CAPPlugin.h"
|
|
2
|
+
#import "CAPBridgedJSTypes.h"
|
|
3
|
+
#import <Capacitor/Capacitor-Swift.h>
|
|
4
|
+
#import <Foundation/Foundation.h>
|
|
5
|
+
|
|
6
|
+
@implementation CAPPlugin
|
|
7
|
+
|
|
8
|
+
-(instancetype) initWithBridge:(id<CAPBridgeProtocol>)bridge pluginId:(NSString *)pluginId pluginName:(NSString *)pluginName {
|
|
9
|
+
self.bridge = bridge;
|
|
10
|
+
self.webView = bridge.webView;
|
|
11
|
+
self.pluginId = pluginId;
|
|
12
|
+
self.pluginName = pluginName;
|
|
13
|
+
self.eventListeners = [[NSMutableDictionary alloc] init];
|
|
14
|
+
self.retainedEventArguments = [[NSMutableDictionary alloc] init];
|
|
15
|
+
self.shouldStringifyDatesInCalls = true;
|
|
16
|
+
return self;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
-(NSString *) getId {
|
|
20
|
+
return self.pluginName;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (BOOL)getBool:(CAPPluginCall *)call field:(NSString *)field defaultValue:(BOOL)defaultValue {
|
|
24
|
+
NSNumber* value = [call getNumber:field defaultValue:[NSNumber numberWithBool:defaultValue]];
|
|
25
|
+
return [value boolValue];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
- (NSString *) getString:(CAPPluginCall *)call field:(NSString *)field defaultValue:(NSString *)defaultValue {
|
|
29
|
+
return [call getString:field defaultValue:defaultValue];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
-(id)getConfigValue:(NSString *)key __deprecated {
|
|
33
|
+
return [self.bridge.config getPluginConfigValue:self.pluginName :key];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
-(PluginConfig*)getConfig {
|
|
37
|
+
return [self.bridge.config getPluginConfig:self.pluginName];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
-(void)load {}
|
|
41
|
+
|
|
42
|
+
- (void)addEventListener:(NSString *)eventName listener:(CAPPluginCall *)listener {
|
|
43
|
+
NSMutableArray *listenersForEvent = [self.eventListeners objectForKey:eventName];
|
|
44
|
+
if(listenersForEvent == nil || [listenersForEvent count] == 0) {
|
|
45
|
+
listenersForEvent = [[NSMutableArray alloc] initWithObjects:listener, nil];
|
|
46
|
+
[self.eventListeners setValue:listenersForEvent forKey:eventName];
|
|
47
|
+
|
|
48
|
+
[self sendRetainedArgumentsForEvent:eventName];
|
|
49
|
+
} else {
|
|
50
|
+
[listenersForEvent addObject:listener];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
- (void)sendRetainedArgumentsForEvent:(NSString *)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
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
- (void)removeEventListener:(NSString *)eventName listener:(CAPPluginCall *)listener {
|
|
69
|
+
NSMutableArray *listenersForEvent = [self.eventListeners objectForKey:eventName];
|
|
70
|
+
if(!listenersForEvent) { return; }
|
|
71
|
+
NSUInteger listenerIndex = [listenersForEvent indexOfObject:listener];
|
|
72
|
+
if(listenerIndex == NSNotFound) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
[listenersForEvent removeObjectAtIndex:listenerIndex];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
- (void)notifyListeners:(NSString *)eventName data:(NSDictionary<NSString *,id> *)data {
|
|
79
|
+
[self notifyListeners:eventName data:data retainUntilConsumed:NO];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
- (void)notifyListeners:(NSString *)eventName data:(NSDictionary<NSString *,id> *)data retainUntilConsumed:(BOOL)retain {
|
|
83
|
+
NSArray<CAPPluginCall *> *listenersForEvent = [self.eventListeners objectForKey:eventName];
|
|
84
|
+
if(listenersForEvent == nil || [listenersForEvent count] == 0) {
|
|
85
|
+
if (retain == YES) {
|
|
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];
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
for (int i=0; i < listenersForEvent.count; i++) {
|
|
97
|
+
CAPPluginCall *call = listenersForEvent[i];
|
|
98
|
+
if (call != nil) {
|
|
99
|
+
CAPPluginCallResult *result = [[CAPPluginCallResult alloc] init:data];
|
|
100
|
+
call.successHandler(result, call);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
- (void)addListener:(CAPPluginCall *)call {
|
|
106
|
+
NSString *eventName = [call.options objectForKey:@"eventName"];
|
|
107
|
+
[call setKeepAlive:TRUE];
|
|
108
|
+
[self addEventListener:eventName listener:call];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
- (void)removeListener:(CAPPluginCall *)call {
|
|
112
|
+
NSString *eventName = [call.options objectForKey:@"eventName"];
|
|
113
|
+
NSString *callbackId = [call.options objectForKey:@"callbackId"];
|
|
114
|
+
CAPPluginCall *storedCall = [self.bridge savedCallWithID:callbackId];
|
|
115
|
+
[self removeEventListener:eventName listener:storedCall];
|
|
116
|
+
[self.bridge releaseCallWithID:callbackId];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
- (void)removeAllListeners:(CAPPluginCall *)call {
|
|
120
|
+
[self.eventListeners removeAllObjects];
|
|
121
|
+
[call resolve];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
- (NSArray<CAPPluginCall *>*)getListeners:(NSString *)eventName {
|
|
125
|
+
NSArray<CAPPluginCall *>* listeners = [self.eventListeners objectForKey:eventName];
|
|
126
|
+
return listeners;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
- (BOOL)hasListeners:(NSString *)eventName {
|
|
130
|
+
NSArray<CAPPluginCall *>* listeners = [self.eventListeners objectForKey:eventName];
|
|
131
|
+
|
|
132
|
+
if (listeners == nil) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return [listeners count] > 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
- (void)checkPermissions:(CAPPluginCall *)call {
|
|
139
|
+
[call resolve];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
- (void)requestPermissions:(CAPPluginCall *)call {
|
|
143
|
+
[call resolve];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Configure popover sourceRect, sourceView and permittedArrowDirections to show it centered
|
|
148
|
+
*/
|
|
149
|
+
-(void)setCenteredPopover:(UIViewController *) vc {
|
|
150
|
+
if (self.bridge.viewController != nil) {
|
|
151
|
+
vc.popoverPresentationController.sourceRect = CGRectMake(self.bridge.viewController.view.center.x, self.bridge.viewController.view.center.y, 0, 0);
|
|
152
|
+
vc.popoverPresentationController.sourceView = self.bridge.viewController.view;
|
|
153
|
+
vc.popoverPresentationController.permittedArrowDirections = 0;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
-(void)setCenteredPopover:(UIViewController* _Nonnull) vc size:(CGSize) size {
|
|
158
|
+
if (self.bridge.viewController != nil) {
|
|
159
|
+
vc.popoverPresentationController.sourceRect = CGRectMake(self.bridge.viewController.view.center.x, self.bridge.viewController.view.center.y, 0, 0);
|
|
160
|
+
vc.preferredContentSize = size;
|
|
161
|
+
vc.popoverPresentationController.sourceView = self.bridge.viewController.view;
|
|
162
|
+
vc.popoverPresentationController.permittedArrowDirections = 0;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
-(BOOL)supportsPopover {
|
|
167
|
+
return YES;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
- (NSNumber*)shouldOverrideLoad:(WKNavigationAction*)navigationAction {
|
|
171
|
+
return nil;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
- (BOOL)handleWKWebViewURLAuthenticationChallenge:(NSURLAuthenticationChallenge* _Nonnull)challenge completionHandler:(void (^_Nonnull)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler {
|
|
175
|
+
return NO;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
@end
|
|
180
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
@class CAPPluginCall;
|
|
4
|
+
@class CAPPluginCallResult;
|
|
5
|
+
@class CAPPluginCallError;
|
|
6
|
+
|
|
7
|
+
typedef void(^CAPPluginCallSuccessHandler)(CAPPluginCallResult *result, CAPPluginCall* call);
|
|
8
|
+
typedef void(^CAPPluginCallErrorHandler)(CAPPluginCallError *error);
|
|
9
|
+
|
|
10
|
+
@interface CAPPluginCall : NSObject
|
|
11
|
+
|
|
12
|
+
@property (nonatomic, assign) BOOL isSaved DEPRECATED_MSG_ATTRIBUTE("Use 'keepAlive' instead.");
|
|
13
|
+
@property (nonatomic, assign) BOOL keepAlive;
|
|
14
|
+
@property (nonatomic, strong) NSString *callbackId;
|
|
15
|
+
@property (nonatomic, strong) NSString *methodName;
|
|
16
|
+
@property (nonatomic, strong) NSDictionary *options;
|
|
17
|
+
@property (nonatomic, copy) CAPPluginCallSuccessHandler successHandler;
|
|
18
|
+
@property (nonatomic, copy) CAPPluginCallErrorHandler errorHandler;
|
|
19
|
+
|
|
20
|
+
- (instancetype)initWithCallbackId:(NSString *)callbackId options:(NSDictionary *)options success:(CAPPluginCallSuccessHandler)success error:(CAPPluginCallErrorHandler)error DEPRECATED_MSG_ATTRIBUTE("Specify the method name as well.");
|
|
21
|
+
|
|
22
|
+
- (instancetype)initWithCallbackId:(NSString *)callbackId methodName:(NSString *)methodName options:(NSDictionary *)options success:(CAPPluginCallSuccessHandler)success error:(CAPPluginCallErrorHandler)error;
|
|
23
|
+
|
|
24
|
+
- (void)save DEPRECATED_MSG_ATTRIBUTE("Use the 'keepAlive' property instead.");
|
|
25
|
+
@end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import "CAPPluginCall.h"
|
|
3
|
+
|
|
4
|
+
@implementation CAPPluginCall
|
|
5
|
+
|
|
6
|
+
- (instancetype)initWithCallbackId:(NSString *)callbackId options:(NSDictionary *)options success:(CAPPluginCallSuccessHandler) success error:(CAPPluginCallErrorHandler) error __deprecated {
|
|
7
|
+
self.callbackId = callbackId;
|
|
8
|
+
self.methodName = @"";
|
|
9
|
+
self.options = options;
|
|
10
|
+
self.successHandler = success;
|
|
11
|
+
self.errorHandler = error;
|
|
12
|
+
return self;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
- (instancetype)initWithCallbackId:(NSString *)callbackId methodName:(NSString *)methodName options:(NSDictionary *)options success:(CAPPluginCallSuccessHandler) success error:(CAPPluginCallErrorHandler) error {
|
|
16
|
+
self.callbackId = callbackId;
|
|
17
|
+
self.methodName = methodName;
|
|
18
|
+
self.options = options;
|
|
19
|
+
self.successHandler = success;
|
|
20
|
+
self.errorHandler = error;
|
|
21
|
+
return self;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
- (BOOL)isSaved {
|
|
25
|
+
return self.keepAlive;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
- (void)setIsSaved:(BOOL)saved {
|
|
29
|
+
self.keepAlive = saved;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
- (void)save {
|
|
33
|
+
self.keepAlive = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
@available(*, deprecated, renamed: "PluginCallResultData")
|
|
4
|
+
public typealias PluginCallErrorData = [String: Any]
|
|
5
|
+
@available(*, deprecated, renamed: "PluginCallResultData")
|
|
6
|
+
public typealias PluginResultData = [String: Any]
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Swift niceties for CAPPluginCall
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
extension CAPPluginCall: JSValueContainer {
|
|
13
|
+
public var jsObjectRepresentation: JSObject {
|
|
14
|
+
return options as? JSObject ?? [:]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@objc extension CAPPluginCall: BridgedJSValueContainer {
|
|
19
|
+
public var dictionaryRepresentation: NSDictionary {
|
|
20
|
+
return options as NSDictionary
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public static var jsDateFormatter: ISO8601DateFormatter = {
|
|
24
|
+
return ISO8601DateFormatter()
|
|
25
|
+
}()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@objc public extension CAPPluginCall {
|
|
29
|
+
@available(*, deprecated, message: "Presence of a key should not be considered significant. Use typed accessors to check the value instead.")
|
|
30
|
+
func hasOption(_ key: String) -> Bool {
|
|
31
|
+
guard let value = options[key] else {
|
|
32
|
+
return false
|
|
33
|
+
}
|
|
34
|
+
return !(value is NSNull)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
func resolve() {
|
|
38
|
+
successHandler(CAPPluginCallResult(nil), self)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
func resolve(_ data: PluginCallResultData = [:]) {
|
|
42
|
+
successHandler(CAPPluginCallResult(data), self)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
func reject(_ message: String, _ code: String? = nil, _ error: Error? = nil, _ data: PluginCallResultData? = nil) {
|
|
46
|
+
errorHandler(CAPPluginCallError(message: message, code: code, error: error, data: data))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
func unimplemented() {
|
|
50
|
+
unimplemented("not implemented")
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
func unimplemented(_ message: String) {
|
|
54
|
+
errorHandler(CAPPluginCallError(message: message, code: "UNIMPLEMENTED", error: nil, data: [:]))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
func unavailable() {
|
|
58
|
+
unavailable("not available")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
func unavailable(_ message: String) {
|
|
62
|
+
errorHandler(CAPPluginCallError(message: message, code: "UNAVAILABLE", error: nil, data: [:]))
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// MARK: Codable Support
|
|
67
|
+
public extension CAPPluginCall {
|
|
68
|
+
/// Encodes the given value to a ``JSObject`` and resolves the call. If an error is thrown during encoding, ``reject(_:_:_:_:)`` is called.
|
|
69
|
+
/// - Parameters:
|
|
70
|
+
/// - data: The value to encode
|
|
71
|
+
/// - encoder: The encoder to use. Defaults to `JSValueEncoder()`
|
|
72
|
+
/// - messageForRejectionFromError: A closure that takes the error thrown from ``JSValueEncoder/encodeJSObject(_:)``
|
|
73
|
+
/// and returns a string to be provided to ``reject(_:_:_:_:)``. Defaults to a function that returns "Failed encoding response".
|
|
74
|
+
func resolve<T: Encodable>(
|
|
75
|
+
with data: T,
|
|
76
|
+
encoder: JSValueEncoder = JSValueEncoder(),
|
|
77
|
+
messageForRejectionFromError: (Error) -> String = { _ in "Failed encoding response" }
|
|
78
|
+
) {
|
|
79
|
+
do {
|
|
80
|
+
let encoded = try encoder.encodeJSObject(data)
|
|
81
|
+
resolve(encoded)
|
|
82
|
+
} catch {
|
|
83
|
+
let message = messageForRejectionFromError(error)
|
|
84
|
+
reject(message, nil, error)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/// Decodes the options to the given type.
|
|
89
|
+
/// - Parameters:
|
|
90
|
+
/// - type: The type to decode to.
|
|
91
|
+
/// - decoder: The decoder to use. Defaults to `JSValueDecoder()`.
|
|
92
|
+
/// - Throws: If the options cannot be decoded.
|
|
93
|
+
/// - Returns: The decoded value.
|
|
94
|
+
func decode<T: Decodable>(_ type: T.Type, decoder: JSValueDecoder = JSValueDecoder()) throws -> T {
|
|
95
|
+
try decoder.decode(type, from: options as? JSObject ?? [:])
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#import "CAPPluginCall.h"
|
|
2
|
+
#import "CAPPlugin.h"
|
|
3
|
+
|
|
4
|
+
typedef enum {
|
|
5
|
+
CAPPluginMethodArgumentNotNullable,
|
|
6
|
+
CAPPluginMethodArgumentNullable
|
|
7
|
+
} CAPPluginMethodArgumentNullability;
|
|
8
|
+
|
|
9
|
+
typedef NSString CAPPluginReturnType;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents a single argument to a plugin method.
|
|
13
|
+
*/
|
|
14
|
+
@interface CAPPluginMethodArgument : NSObject
|
|
15
|
+
|
|
16
|
+
@property (nonatomic, copy) NSString *name;
|
|
17
|
+
@property (nonatomic, assign) CAPPluginMethodArgumentNullability nullability;
|
|
18
|
+
|
|
19
|
+
- (instancetype)initWithName:(NSString *)name nullability:(CAPPluginMethodArgumentNullability)nullability type:(NSString *)type;
|
|
20
|
+
|
|
21
|
+
@end
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Represents a method that a plugin supports, with the ability
|
|
25
|
+
* to compute selectors and invoke the method.
|
|
26
|
+
*/
|
|
27
|
+
@interface CAPPluginMethod : NSObject
|
|
28
|
+
|
|
29
|
+
@property (nonatomic, assign) SEL selector;
|
|
30
|
+
@property (nonatomic, strong) NSString *name; // Raw method name
|
|
31
|
+
@property (nonatomic, strong) CAPPluginReturnType *returnType; // Return type of method (i.e. callback/promise/sync)
|
|
32
|
+
|
|
33
|
+
- (instancetype)initWithName:(NSString *)name returnType:(CAPPluginReturnType *)returnType;
|
|
34
|
+
- (instancetype)initWithSelector:(SEL)selector returnType:(CAPPluginReturnType *)returnType;
|
|
35
|
+
|
|
36
|
+
@end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#import <Capacitor/Capacitor-Swift.h>
|
|
2
|
+
#import "CAPPluginMethod.h"
|
|
3
|
+
|
|
4
|
+
typedef void(^CAPCallback)(id _arg, NSInteger index);
|
|
5
|
+
|
|
6
|
+
@implementation CAPPluginMethodArgument
|
|
7
|
+
|
|
8
|
+
- (instancetype)initWithName:(NSString *)name nullability:(CAPPluginMethodArgumentNullability)nullability type:(NSString *)type {
|
|
9
|
+
self.name = name;
|
|
10
|
+
self.nullability = nullability;
|
|
11
|
+
return self;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
@implementation CAPPluginMethod {
|
|
17
|
+
// NSInvocation's retainArguments doesn't work with our arguments
|
|
18
|
+
// so we have to retain args manually
|
|
19
|
+
NSMutableArray *_manualRetainArgs;
|
|
20
|
+
// Retain invocation instance
|
|
21
|
+
NSInvocation *_invocation;
|
|
22
|
+
NSMutableArray *_methodArgumentCallbacks;
|
|
23
|
+
CAPPluginCall *_call;
|
|
24
|
+
SEL _selector;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
-(instancetype)initWithName:(NSString *)name returnType:(CAPPluginReturnType *)returnType {
|
|
28
|
+
self.name = name;
|
|
29
|
+
self.selector = NSSelectorFromString([name stringByAppendingString:@":"]);
|
|
30
|
+
self.returnType = returnType;
|
|
31
|
+
return self;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
-(instancetype)initWithSelector:(SEL) selector returnType:(CAPPluginReturnType *)returnType {
|
|
35
|
+
// need to drop the : from the selector string
|
|
36
|
+
NSString* rawSelString = NSStringFromSelector(selector);
|
|
37
|
+
self.name = [rawSelString substringToIndex:[rawSelString length] - 1];
|
|
38
|
+
self.selector = selector;
|
|
39
|
+
self.returnType = returnType;
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@end
|
|
44
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CAPPluginMethod.swift
|
|
3
|
+
// Capacitor
|
|
4
|
+
//
|
|
5
|
+
// Created by Steven Sherry on 4/18/24.
|
|
6
|
+
// Copyright © 2024 Drifty Co. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
extension CAPPluginMethod {
|
|
10
|
+
public enum ReturnType: String {
|
|
11
|
+
case promise, callback, none
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public convenience init(_ selector: Selector, returnType: ReturnType = .promise) {
|
|
15
|
+
self.init(selector: selector, returnType: returnType.rawValue)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
//! Project version number for bridge.
|
|
4
|
+
FOUNDATION_EXPORT double CapacitorVersionNumber;
|
|
5
|
+
|
|
6
|
+
//! Project version string for bridge.
|
|
7
|
+
FOUNDATION_EXPORT const unsigned char CapacitorVersionString[];
|
|
8
|
+
|
|
9
|
+
#import <Capacitor/CAPPlugin.h>
|
|
10
|
+
#import <Capacitor/CAPPluginCall.h>
|
|
11
|
+
#import <Capacitor/CAPBridgedPlugin.h>
|
|
12
|
+
#import <Capacitor/CAPPluginMethod.h>
|
|
13
|
+
#import <Capacitor/CAPInstanceDescriptor.h>
|
|
14
|
+
#import <Capacitor/CAPInstanceConfiguration.h>
|
|
15
|
+
|