ios add share file
This commit is contained in:
parent
85b032bedc
commit
8049474db8
5
.prettierrc
Normal file
5
.prettierrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"singleQuote": true,
|
||||||
|
"printWidth": 100,
|
||||||
|
"trailingComma": "all"
|
||||||
|
}
|
||||||
10
index.d.ts
vendored
10
index.d.ts
vendored
@ -161,4 +161,14 @@ declare module 'react-native-wechat-lib' {
|
|||||||
export function chooseInvoice(
|
export function chooseInvoice(
|
||||||
data?: ChooseInvoice,
|
data?: ChooseInvoice,
|
||||||
): Promise<{ errCode?: number; errStr?: string; cards: Invoice[] }>;
|
): Promise<{ errCode?: number; errStr?: string; cards: Invoice[] }>;
|
||||||
|
|
||||||
|
export interface ShareFileMetadata {
|
||||||
|
url: string;
|
||||||
|
title?: string;
|
||||||
|
ext?: string;
|
||||||
|
scene?: WXScene;
|
||||||
|
}
|
||||||
|
export function shareFile(
|
||||||
|
data: ShareFileMetadata,
|
||||||
|
): Promise<{ errCode?: number; errStr?: string }>;
|
||||||
}
|
}
|
||||||
|
|||||||
19
index.js
19
index.js
@ -159,6 +159,7 @@ const nativeShareMiniProgram = wrapApi(WeChat.shareMiniProgram);
|
|||||||
const nativeSubscribeMessage = wrapApi(WeChat.subscribeMessage);
|
const nativeSubscribeMessage = wrapApi(WeChat.subscribeMessage);
|
||||||
|
|
||||||
const nativeChooseInvoice = wrapApi(WeChat.chooseInvoice);
|
const nativeChooseInvoice = wrapApi(WeChat.chooseInvoice);
|
||||||
|
const nativeShareFile = wrapApi(WeChat.shareFile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method sendAuthRequest
|
* @method sendAuthRequest
|
||||||
@ -217,6 +218,24 @@ export function chooseInvoice(data) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Share File
|
||||||
|
* @method shareFile
|
||||||
|
* @param {Object} data
|
||||||
|
*/
|
||||||
|
export function shareFile(data) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
nativeShareFile(data);
|
||||||
|
emitter.once('SendMessageToWX.Resp', (resp) => {
|
||||||
|
if (resp.errCode === 0) {
|
||||||
|
resolve(resp);
|
||||||
|
} else {
|
||||||
|
reject(new WechatError(resp));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Share image
|
* Share image
|
||||||
* @method shareImage
|
* @method shareImage
|
||||||
|
|||||||
@ -260,6 +260,33 @@ RCT_EXPORT_METHOD(chooseInvoice:(NSDictionary *)data
|
|||||||
[WXApi sendReq:req completion:completion];
|
[WXApi sendReq:req completion:completion];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分享文件
|
||||||
|
RCT_EXPORT_METHOD(shareFile:(NSDictionary *)data
|
||||||
|
:(RCTResponseSenderBlock)callback)
|
||||||
|
{
|
||||||
|
NSString *url = data[@"url"];
|
||||||
|
WXFileObject *file = [[WXFileObject alloc] init];
|
||||||
|
file.fileExtension = data[@"ext"];
|
||||||
|
NSData *fileData = [NSData dataWithContentsOfURL:[NSURL URLWithString: url]];
|
||||||
|
file.fileData = fileData;
|
||||||
|
|
||||||
|
WXMediaMessage *message = [WXMediaMessage message];
|
||||||
|
message.title = data[@"title"];
|
||||||
|
message.mediaObject = file;
|
||||||
|
|
||||||
|
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
|
||||||
|
req.bText = NO;
|
||||||
|
req.message = message;
|
||||||
|
req.scene = [data[@"scene"] integerValue];
|
||||||
|
void ( ^ completion )( BOOL );
|
||||||
|
completion = ^( BOOL success )
|
||||||
|
{
|
||||||
|
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
[WXApi sendReq:req completion:completion];
|
||||||
|
}
|
||||||
|
|
||||||
// 分享图片
|
// 分享图片
|
||||||
RCT_EXPORT_METHOD(shareImage:(NSDictionary *)data
|
RCT_EXPORT_METHOD(shareImage:(NSDictionary *)data
|
||||||
:(RCTResponseSenderBlock)callback)
|
:(RCTResponseSenderBlock)callback)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user