PGPlugin.h
12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#define PDRPluginHandleOpenURLNotification @"PDRPluginHandleOpenURLNotification"
typedef enum {
PDRCommandStatusNoResult = 0,
PDRCommandStatusOK,
PDRCommandStatusError
} PDRCommandStatus;
@class PDRCoreApp;
@class PDRCoreAppFrame;
/** Native执行结果
*/
@interface PDRPluginResult : NSObject {
}
@property (nonatomic, strong, readonly) NSNumber* status;
@property (nonatomic, strong, readonly) id message;
@property (nonatomic, assign) BOOL keepCallback;
-(PDRPluginResult*) init;
+(PDRPluginResult*) resultWithStatus: (PDRCommandStatus) statusOrdinal;
/**
@brief 返回JS字符串
@param statusOrdinal 结果码
@param theMessage 字符串结果
@return PDRPluginResult*
*/
+(PDRPluginResult*) resultWithStatus: (PDRCommandStatus) statusOrdinal messageAsString: (NSString*) theMessage;
/**
@brief 返回JS数组
@param statusOrdinal 结果码
@param theMessage 字符串结果
@return PDRPluginResult*
*/
+(PDRPluginResult*) resultWithStatus: (PDRCommandStatus) statusOrdinal messageAsArray: (NSArray*) theMessage;
+(PDRPluginResult*) resultWithStatus: (PDRCommandStatus) statusOrdinal messageAsInt: (int) theMessage;
+(PDRPluginResult*) resultWithStatus: (PDRCommandStatus) statusOrdinal messageAsDouble: (double) theMessage;
+(PDRPluginResult*) resultWithStatus: (PDRCommandStatus) statusOrdinal messageAsDictionary: (NSDictionary*) theMessage;
+(PDRPluginResult*) resultWithStatus: (PDRCommandStatus) statusOrdinal messageToErrorObject: (int) errorCode;
/**
@brief 返回错误对象
@param statusOrdinal 结果码
@param errorCode 错误码
@param message 错误描述
@return PDRPluginResult*
*/
+(PDRPluginResult*) resultWithStatus: (PDRCommandStatus) statusOrdinal
messageToErrorObject: (int) errorCode
withMessage:(NSString*)message;
+(PDRPluginResult*) resultWithInnerError:(int) errorCode
withMessage:(NSString*)message;
/**
@brief 返回JSON格式的结果
@return NSString*
*/
-(NSString*) toJSONString;
@end
enum {
PGPluginErrorInner = -100,
PGPluginErrorUnknown = -99,
PGPluginErrorAuthDenied = -10,
PGPluginErrorNoInstall = -8,
PGPluginErrorConfig = -7,
PGPluginErrorNet = -6,
PGPluginErrorIO = -5,
PGPluginErrorFileNotFound = -4,
PGPluginErrorNotSupport = -3,
PGPluginErrorUserCancel = -2,
PGPluginErrorInvalidArgument = -1,
PGPluginOK = 0,
PGPluginErrorFileExist,
PGPluginErrorFileCreateFail,
PGPluginErrorZipFail,
PGPluginErrorUnZipFail,
PGPluginErrorNotAllowWrite,
PGPluginErrorNotAllowRead,
PGPluginErrorBusy,
PGPluginErrorNotPermission,
PGPluginErrorNext
};
typedef NS_ENUM(NSInteger, PGPluginAuthorizeStatus) {
PGPluginAuthorizeStatusNotDetermined,
PGPluginAuthorizeStatusDenied,
PGPluginAuthorizeStatusRestriction,
PGPluginAuthorizeStatusAuthorized
};
@protocol PGPluginAuthorize <NSObject>
- (PGPluginAuthorizeStatus)authorizeStatus;
@end
@protocol PGPlugin <NSObject>
@optional
//事件通知类
///App(5+ App)webview关闭/应用关闭/应用启动
- (void) onAppFrameWillClose:(PDRCoreAppFrame*)theAppframe;
- (void) onAppFrameDidShow:(PDRCoreAppFrame*)theAppframe;
- (void) onAppFrameDidHidden:(PDRCoreAppFrame*)theAppframe;
- (void) onAppClose;
- (void) onAppStarted:(NSDictionary*)options;
- (void) onAppUpgradesNoClose;
- (void) onNeedLayout;
///Application(iOS App)终止/进入后台/进入前台
- (void) onAppTerminate;
- (void) onAppEnterBackground;
- (void) onAppEnterForeground;
- (void) onMemoryWarning;
@end
/** PDR插件基类
扩展插件都应该从该类继承
*/
@interface PGPlugin : NSObject<PGPluginAuthorize,PGPlugin>
/// 插件运行的窗口对象 <br/>参考: `PDRCoreAppFrame`
@property (nonatomic, assign) PDRCoreAppFrame* JSFrameContext;
/// 插件运行的应用对象 <br/>参考: `PDRCoreApp`
@property (nonatomic, assign) PDRCoreApp* appContext;
/// 插件错误码参考地址
@property (nonatomic, copy) NSString *errorURL;
@property (nonatomic, copy) NSString *sdkErrorURL;
/// 插件名字
@property (nonatomic, copy) NSString *name;
/// 插件描述
@property (nonatomic, copy) NSString *content;
- (PGPlugin*) initWithWebView:(PDRCoreAppFrame*)theWebView withAppContxt:(PDRCoreApp*)app;
- (UIViewController*) rootViewController;
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion;
- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion;
- (void) handleOpenURL:(NSNotification*)notification;
- (NSString*)getUniversalLink;
///创建插件时调用
- (void) onCreate;
///销毁插件前调用
- (void) onDestroy;
- (id) onMessage:(id)payload;
- (id) postMessage:(id)payload toPlugin:(NSString*)name inWebview:(NSString*)webview;
- (NSString*)plusObject;
- (NSString*)errorMsgWithCode:(int)errorCode;
//将5+应用转化为系统路径
//支持5+路径_doc/ _www/ _document/ _download/
//file://
//html相对路径
- (NSString*) h5Path2SysPath:(NSString*)path;
- (UIScrollView*)webviewScrollView;
- (NSString*)JSFrameContextID;
//同步执行时放回int值
- (NSData*) resultWithInt:(int)value;
- (NSData*) resultWithString:(NSString*)value;
- (NSData*) resultWithBool:(BOOL)value;
- (NSData*) resultWithDouble:(double)value;
- (NSData*) resultWithJSON:(NSDictionary*)dict;
- (NSData*) resultWithArray:(NSArray*)array;
- (NSData*) resultWithNull;
- (NSData*) resultWithNaN;
- (NSData*) resultWithUndefined;
/**
@brief 同步调用JavaScript回调函数 参考:`toCallback:withReslut:`
*/
-(void) toSyncCallback: (NSString*) callbackId withReslut:(NSString*)message;
/**
@brief 异步调用JavaScript回调函数
@param callbackId 回调ID
@param message JSON格式结果 参考:`toJSONString`
*/
-(void) toCallback: (NSString*) callbackId withReslut:(NSString*)message;
-(void) toCallback: (NSString*) callbackId withReslut:(NSString*)message inWebview:(NSString*)webviewId;
///调用JS层错误回调
-(void) toErrorCallback: (NSString*) callbackId withCode:(int)errorCode;
-(void) toErrorCallback: (NSString*) callbackId withCode:(int)errorCode withMessage:(NSString*)message;
-(void) toErrorCallback: (NSString*) callbackId withCode:(int)errorCode withMessage:(NSString*)message keepCallback:(BOOL)keepCallback;
-(void) toErrorCallback: (NSString*) callbackId withCode:(int)errorCode withMessage:(NSString*)message withResult:(NSString*)resultStr keepCallback:(BOOL)keepCallback;
-(void) toErrorCallback: (NSString*) callbackId withInnerCode:(int)errorCode withMessage:(NSString*)message;
-(void) toErrorCallback: (NSString*) callbackId withInnerCode:(int)errorCode withMessage:(NSString*)message keepCallback:(BOOL)keepCallback;
///将OC NSError转化为H5+Error
-(void) toErrorCallback: (NSString*) callbackId
withNSError:(NSError*)error;
///封装插件使用的SDK产生的错误信息
///code:-100
///message:[self.name self.contexnt:errorCode]message,self.sdkErrorURL
-(void) toErrorCallback: (NSString*) callbackId
withSDKError:(int)errorCode
withMessage:(NSString*)message;
-(void) toErrorCallback: (NSString*) callbackId
withSDKNSError:(NSError*)error;
-(void) toErrorCallback: (NSString*) callbackId
withMoudleName:(NSString*)moudleName
withCode:(int)errorCode
withMessage:(NSString*)message withURL:(NSString*)url;
-(void) toSucessCallback: (NSString*) callbackId withInt:(int)intValue;
-(void) toSucessCallback: (NSString*) callbackId withInt:(int)errorCode keepCallback:(BOOL)keepCallback;
-(void) toSucessCallback: (NSString*) callbackId withDouble:(double)doubleValue;
-(void) toSucessCallback: (NSString*) callbackId withDouble:(double)doubleValue keepCallback:(BOOL)keepCallback;
-(void) toSucessCallback: (NSString*) callbackId withString:(NSString*)stringValue;
-(void) toSucessCallback: (NSString*) callbackId withString:(NSString*)stringValue keepCallback:(BOOL)keepCallback;
-(void) toSucessCallback: (NSString*) callbackId withJSON:(NSDictionary*)jsonValue;
-(void) toSucessCallback: (NSString*) callbackId withJSON:(NSDictionary*)jsonValue keepCallback:(BOOL)keepCallback;
-(void) toSucessCallback: (NSString*) callbackId withArray:(NSArray*)arrayValue;
-(void) toSucessCallback: (NSString*) callbackId withArray:(NSArray*)arrayValue keepCallback:(BOOL)keepCallback;
-(void) toSucessCallback: (NSString*) callbackId
inWebview:(NSString*)webviewId
withJSON:(NSDictionary*)jsonValue
keepCallback:(BOOL)keepCallback;
- (void) writeJavascript:(NSString*)javascript;
- (void) writeJavascript:(NSString*)javascript completionHandler:(void (^)(id, NSError*))completionHandler;
- (void) asyncWriteJavascript:(NSString*)javascript;
- (void) asyncWriteJavascript:(NSString*)javascript inWebview:(NSString*)webviewId;
- (PGPluginAuthorizeStatus)authorizeStatus;
@end
@interface PGPluginParamHelper : NSObject
+(BOOL)getBoolValue:(id)jsValue defalut:(BOOL)defalutValue;
+(BOOL)getBoolValueInDict:(NSDictionary*)jsValue
forKey:(NSString*)key defalut:(float)defalutValue;
+(BOOL)getBoolValueInDict:(NSDictionary*)jsValue
forKey:(NSString*)key secondKey:(NSString*)secondKey defalut:(float)defalutValue;
+(BOOL)isValue:(id)jsValue sameToValue:(NSString*)equalValue defalut:(BOOL)defalutValue;
+(BOOL)isValueInDict:(NSDictionary*)dict
forKey:(NSString*)key
sameToValue:(NSString*)equalValue
defalut:(BOOL)defalutValue;
+(int)getIntValue:(id)jsValue defalut:(int)defalutValue;
+(int)getIntValueInDict:(NSDictionary*)jsValue
forKey:(NSString*)key
defalut:(int)defalutValue;
+(float)getFloatValue:(id)jsValue defalut:(float)defalutValue;
+(float)getFloatValueInDict:(NSDictionary*)jsValue
forKey:(NSString*)key;
+(float)getFloatValueInDict:(NSDictionary*)jsValue
forKey:(NSString*)key defalut:(float)defalutValue;
+(CGFloat)getPixelValueInDict:(NSDictionary*)jsValue
forKey:(NSString*)key defalut:(CGFloat)defalutValue;
+(BOOL)isAutoValue:(id)jsValue;
///String
+(BOOL)isEmptyString:(NSString*)jsValue;
+(NSString*)getStringValue:(id)jsValue;
+(NSString*)getLowercaseStringValue:(id)jsValue defalut:(NSString*)defalutValue;
+(NSString*)getStringValue:(id)jsValue defalut:(NSString*)defalutValue;
+(NSString*)getStringValueInDict:(NSDictionary*)jsValue
forKey:(NSString*)key;
+(NSString*)getStringValueInDict:(NSDictionary*)jsValue
forKey:(NSString*)key defalut:(NSString*)defalutValue;
+(NSString*)getStringValueInDict:(NSDictionary*)jsValue
forKey:(NSString*)key
testEmptyString:(BOOL)testEmpty
defalut:(NSString*)defalutValue;
+ (int)getEnumValueCaseInsensitive:(NSString*)key inMap:(NSDictionary*)enumvalue defautValue:(int)defaultValue ;
+(NSDictionary*)getJSONValue:(id)jsValue defalut:(NSDictionary*)defalutValue;
+(NSDictionary*)getJSONValueInDict:(NSDictionary*)jsValue
forKey:(NSString*)key;
+(NSArray*)getArray:(id)jsValue defalut:(NSArray*)defalutValue;
+(NSArray*)getArrayValueInDict:(NSDictionary*)jsValue
forKey:(NSString*)key defalut:(NSArray*)defalutValue;
+(NSString*)testString:(NSString*)jsValue
inRange:(NSArray*)ranges
defalut:(NSString*)defalutValue;
+(CGFloat)getMeasure:(id)jsValue
withStaff:(CGFloat)withStaff
defalut:(CGFloat)defalutValue;
+(CGFloat)getMeasure:(id)jsValue
withStaff:(CGFloat)withStaff
defalut:(CGFloat)defalutValue
error:(BOOL*)error;
+(UIColor*)getCssColor:(id)jsValue
defalut:(UIColor*)defalutValue;
+(CGFloat)getCssColorForAlph:(id)jsValue
defalut:(CGFloat)defalutValue;
+(NSTextAlignment)getAlign:(NSString*)jsValue
defalut:(NSTextAlignment)defalutValue;
+ (CGRect)getValueFromJSRect:(NSDictionary*)jsRect
withReferenceSize:(CGSize)refSize error:(NSError**)error;
+ (id)getValue:(NSString*)key inMap:(NSDictionary*)enumvalue defautValue:(id)defaultValue;
+ (int)getEnumValue:(NSString*)key inMap:(NSDictionary*)enumvalue defautValue:(int)defaultValue;
+ (NSDictionary*)lowercaseStringKey:(NSDictionary*)dict;
+ (void)pareseStatusbar:(id)statusBar completion:(void(^)(BOOL,UIColor*, BOOL))result;
+ (id)getObjectAtIndex:(NSUInteger)index inArray:(NSArray*)argArray;
@end