IM 即时通讯 (442)
Android (209)
- 初始化&链接 (8)
- 事件&监听处理 (7)
- 用户信息 (13)
- 会话列表 (16)
- 聊天会话 (26)
- 消息处理 (35)
- 自定义消息 (6)
- 音视频 (2)
- 推送&通知 (34)
- 扩展功能 (4)
- 第三方地图 (3)
- 依赖&配置 (9)
- 升级说明 (3)
- 其他 (43)
iOS (168)
- SDK 导入 (10)
- 连接 (8)
- 事件处理 (2)
- 用户信息 (3)
- 会话列表 (14)
- 聊天会话 (44)
- 消息处理 (26)
- 自定义消息 (8)
- 推送&通知 (19)
- 扩展功能 (5)
- 国际化 (4)
- 音视频 (3)
- 其他 (22)
Web (36)
Server (29)
选择 iCloud 文件并发送
选择 iCloud 文件并发送 RCFileMessage 类型消息。
发布时间: 2019-07-18 14:46
回答:
iCloud 选择文件功能
1: 在扩展功能板的点击回调代理方法中判断如果tag是PLUGIN_BOARD_ITEM_FILE_TAG
则拦截,会话页面重写如下方法:
- (void)pluginBoardView:(RCPluginBoardView *)pluginBoardView clickedItemWithTag:(NSInteger)tag;
2:调用如下方法唤起 iCloud 选择界面:
// 根据需求添加具体文件格式 NSArray *documentTypes = @[@"public.content", @"public.text", @"public.source-code", @"public.image", @"public.audiovisual-content", @"com.adobe.pdf", @"com.apple.keynote.key", @"com.microsoft.word.doc", @"com.microsoft.excel.xls", @"com.microsoft.powerpoint.ppt"]; UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeImport]; documentPicker.delegate = self; documentPicker.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:documentPicker animated:YES completion:nil];
3:选择完文件后调用如下方法发出消息:
#pragma mark - UIDocumentPickerDelegate -(void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url { NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil]; NSError *error = nil; [coordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) { NSData *data = [NSData dataWithContentsOfURL:newURL]; if (data.length <= 0) { UIAlertController *alertCtrl = [UIAlertController alertControllerWithTitle:RCEStringFor(@"not_allow_empty") message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:RCEStringFor(@"confirm_btn_title") style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { }]; [alertCtrl addAction:confirmAction]; [self presentViewController:alertCtrl animated:YES completion:nil]; return; } RCFileMessage *fileMsg = [RCFileMessage messageWithFile:[newURL path]]; [self sendMessage:fileMsg pushContent:nil]; [controller dismissViewControllerAnimated:YES completion:nil]; }]; if (error) { NSLog(@"ERROR: read data with "DocumentAtURL" failed"); } }