Skip to content

Commit

Permalink
Merge pull request #362 from miserydx/dev-miserydx
Browse files Browse the repository at this point in the history
[fix] 解决iOS 14不能正常加载fair_extension中的js plugin
  • Loading branch information
wanbing authored Nov 10, 2023
2 parents 8d98832 + f8e8c8b commit 093a1f6
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 195 deletions.
101 changes: 50 additions & 51 deletions fair_extension/assets/plugin/fair_image_picker.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
let FairImagePickerCallback = {};
let FairImagePickerId = 1;
class FairImagePicker {

static photo = 'photo';
static album = 'album';

static getImage(req) {
let selectorId = 'FairImagePickerId' + FairImagePickerId++;
// 设置回调
let reqFunc = {};
if (req.success) {
reqFunc['success'] = req.success;
}
if (req.failure) {
reqFunc['failure'] = req.failure;
}
FairImagePickerCallback[selectorId] = reqFunc;
let typeP = '';
if (req.type) {
typeP = req.type;
}
let reqMap = {
pageName: '#FairKey#',
funcName: 'invokePlugin',
'className':'FairImagePicker#getImage',
args: {
callId: selectorId,
type: typeP,
}
};
invokeFlutterCommonChannel(JSON.stringify(reqMap), function (resp) {
//处理dart端返回的请求结果
let respMap = JSON.parse(resp);
let respArgs = respMap['args'];
let respCallId = respArgs['callId'];
let imagePath = respArgs['imagePath'];
//处理需要返回的结果值
let callback = FairImagePickerCallback[respCallId];
if (callback == null) {
return
}
let successCallback = callback['success'];
let failureCallback = callback['failure'];
if (imagePath != null && successCallback != null) {
successCallback(imagePath);
} else {
if (failureCallback != null) {
failureCallback('');
}
}
//移除回调
FairImagePickerCallback[respCallId] = null;
});
const FairImagePicker = {
photo: 'photo',
album: 'album',
getImage: function (req) {
let selectorId = 'FairImagePickerId' + FairImagePickerId++;
// 设置回调
let reqFunc = {};
if (req.success) {
reqFunc['success'] = req.success;
}
if (req.failure) {
reqFunc['failure'] = req.failure;
}
FairImagePickerCallback[selectorId] = reqFunc;
let typeP = '';
if (req.type) {
typeP = req.type;
}
let reqMap = {
pageName: '#FairKey#',
funcName: 'invokePlugin',
'className': 'FairImagePicker#getImage',
args: {
callId: selectorId,
type: typeP,
}
};
invokeFlutterCommonChannel(JSON.stringify(reqMap), function (resp) {
//处理dart端返回的请求结果
let respMap = JSON.parse(resp);
let respArgs = respMap['args'];
let respCallId = respArgs['callId'];
let imagePath = respArgs['imagePath'];
//处理需要返回的结果值
let callback = FairImagePickerCallback[respCallId];
if (callback == null) {
return
}
let successCallback = callback['success'];
let failureCallback = callback['failure'];
if (imagePath != null && successCallback != null) {
successCallback(imagePath);
} else {
if (failureCallback != null) {
failureCallback('');
}
}
//移除回调
FairImagePickerCallback[respCallId] = null;
});
}
}
146 changes: 72 additions & 74 deletions fair_extension/assets/plugin/fair_net_plugin.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,76 @@
let FairNetCallBack = {};
let callBackId = 0;

class FairNet {

static GET = 'GET';
static POST = 'POST';

static requestData(req) {
let respMap = {};
let id = 'FairNet$' + (callBackId++);
// 设置回调
let reqFunc = {};
if (req.complete) {
reqFunc['complete'] = req.complete;
}
if (req.success) {
reqFunc['success'] = req.success;
}
if (req.failure) {
reqFunc['failure'] = req.failure;
}
FairNetCallBack[id] = reqFunc;
// 处理参数
let method = '';
if (req.method) {
method = req.method;
}
let url = '';
if (req.url) {
url = req.url;
}
let data = {};
if (req.data) {
data = mapOrSetToObject(req.data);
}
let reqMap = {
pageName: '#FairKey#',
funcName: 'invokePlugin',
'className': 'FairNet#requestData',
args: {
callId: id,
method: method,
url: url,
data: data
}
};
invokeFlutterCommonChannel(JSON.stringify(reqMap), (resultStr) =>{
let responseMap = JSON.parse(resultStr);
let data = responseMap['data'];
responseMap['data'] = data.data;
let id = responseMap['callId'];
//处理需要返回的结果值
let callback = FairNetCallBack[id];
if (callback == null) {
return
}
let complete = callback['complete'];
let failure = callback['failure'];
let success = callback['success'];
if (responseMap['statusCode'] === 200) {
if (complete != null) {
complete();
}
if (success != null) {
success(convertObjectLiteralToSetOrMap(responseMap));
}
} else {
if (complete != null) {
complete();
}
if (failure != null) {
failure(responseMap['statusMessage']);
}
}
})
}
const FairNet = {
GET: 'GET',
POST: 'POST',
requestData: function (req) {
let respMap = {};
let id = 'FairNet$' + (callBackId++);
// 设置回调
let reqFunc = {};
if (req.complete) {
reqFunc['complete'] = req.complete;
}
if (req.success) {
reqFunc['success'] = req.success;
}
if (req.failure) {
reqFunc['failure'] = req.failure;
}
FairNetCallBack[id] = reqFunc;
// 处理参数
let method = '';
if (req.method) {
method = req.method;
}
let url = '';
if (req.url) {
url = req.url;
}
let data = {};
if (req.data) {
data = mapOrSetToObject(req.data);
}
let reqMap = {
pageName: '#FairKey#',
funcName: 'invokePlugin',
'className': 'FairNet#requestData',
args: {
callId: id,
method: method,
url: url,
data: data
}
};
invokeFlutterCommonChannel(JSON.stringify(reqMap), (resultStr) => {
let responseMap = JSON.parse(resultStr);
let data = responseMap['data'];
responseMap['data'] = data.data;
let id = responseMap['callId'];
//处理需要返回的结果值
let callback = FairNetCallBack[id];
if (callback == null) {
return
}
let complete = callback['complete'];
let failure = callback['failure'];
let success = callback['success'];
if (responseMap['statusCode'] === 200) {
if (complete != null) {
complete();
}
if (success != null) {
success(convertObjectLiteralToSetOrMap(responseMap));
}
} else {
if (complete != null) {
complete();
}
if (failure != null) {
failure(responseMap['statusMessage']);
}
}
})
}
}
104 changes: 51 additions & 53 deletions fair_extension/assets/plugin/fair_permission.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,55 @@
let FairPermissionCallback = {};
let FairPermissionId = 1;
class FairPermission {

static permissionPhoto = "Permission_Photo";
static permissionPhone = "Permission_Phone";
static permissionAudio = "Permission_Audio";

static requestPermission(req) {
let selectorId = 'FairPermissionId' + FairPermissionId++;
// 设置回调
let reqFunc = {};
if (req.granted) {
reqFunc['granted'] = req.granted;
}
if (req.restricted) {
reqFunc['restricted'] = req.restricted;
}
FairPermissionCallback[selectorId] = reqFunc;
let typeP = '';
if (req.type) {
typeP = req.type;
}
let reqMap = {
pageName: '#FairKey#',
funcName: 'invokePlugin',
'className':'FairPermission#requestPermission',
args: {
callId: selectorId,
type: typeP
}
};
invokeFlutterCommonChannel(JSON.stringify(reqMap), function (resp) {
//处理dart端返回的请求结果
let respMap = JSON.parse(resp);
let respArgs = respMap['args'];
let respCallId = respArgs['callId'];
let isGranted = respArgs['isGranted'];
//处理需要返回的结果值
let callback = FairPermissionCallback[respCallId];
if (callback == null) {
return
}
let grantedCallback = callback['granted'];
let restrictedCallback = callback['restricted'];
if (isGranted && grantedCallback != null) {
grantedCallback();
} else {
if (restrictedCallback != null) {
restrictedCallback();
}
}
//移除回调
FairPermissionCallback[respCallId] = null;
});
const FairPermission = {
permissionPhoto: "Permission_Photo",
permissionPhone: "Permission_Phone",
permissionAudio: "permissionAudio",
requestPermission: function (req) {
let selectorId = 'FairPermissionId' + FairPermissionId++;
// 设置回调
let reqFunc = {};
if (req.granted) {
reqFunc['granted'] = req.granted;
}
if (req.restricted) {
reqFunc['restricted'] = req.restricted;
}
FairPermissionCallback[selectorId] = reqFunc;
let typeP = '';
if (req.type) {
typeP = req.type;
}
let reqMap = {
pageName: '#FairKey#',
funcName: 'invokePlugin',
'className': 'FairPermission#requestPermission',
args: {
callId: selectorId,
type: typeP
}
};
invokeFlutterCommonChannel(JSON.stringify(reqMap), function (resp) {
//处理dart端返回的请求结果
let respMap = JSON.parse(resp);
let respArgs = respMap['args'];
let respCallId = respArgs['callId'];
let isGranted = respArgs['isGranted'];
//处理需要返回的结果值
let callback = FairPermissionCallback[respCallId];
if (callback == null) {
return
}
let grantedCallback = callback['granted'];
let restrictedCallback = callback['restricted'];
if (isGranted && grantedCallback != null) {
grantedCallback();
} else {
if (restrictedCallback != null) {
restrictedCallback();
}
}
//移除回调
FairPermissionCallback[respCallId] = null;
});
}
}
Loading

0 comments on commit 093a1f6

Please sign in to comment.