iOS ShareSDK实现分享——微信分享

article/2025/10/15 4:41:52

最近领导让添加ios 微信分享视频的功能,之前做的只有微信分享本地图片的功能。

查看官网并没有找到答案,后来在其官网论坛中http://bbs.mob.com/thread-20938-1-1.html 这里面发现新版的sdk(v3.2.1)中才添加的微信分享本地文件(mp3、mp4、docx、pdf等)的功能。可以支持就好办了。。

使用集成好的第三方框架可以节省许多代码量。

注意:申请shareSdk的apply,还有各个平台的appkey和appsecert(这真是非常麻烦的事情啊)

集成SDK

1 下载ShareSDK 简洁版(v3.2.1)

目录如下所示:

         

目录结构:

  (1)ShareSDk.framework:核心静态库。(必要)

    (2)  Support 文件夹。其中包含三个文件夹:

   (a) Required (需要的类库) :

----- MOBFoundation.framework:基础功能框架。(必要)
----- ShareSDK.bundle:ShareSDK资源文件。(必要)
----- ShareSDKConnector.framework:用于ShareSDK框架与外部框架连接的代理框架插件。(使用第三方SDK时必要。)
(b) Optional (可选类库):
----- ShareSDKExtension.framework:对ShareSDK功能的扩展框架插件。
(主要提供第三方平台登录、 一键分享、截屏分享、摇一摇分享等相关功能。需要使用以上功能时必要。)
----- ShareSDKInterfaceAdapter.framework:ShareSDK v2.x对简洁版的接口兼容包。
----- ShareSDKUI.bundle:分享菜单栏和分享编辑页面资源包。(如果自定义这些UI可直接移除)
----- ShareSDKUI.framework:分享菜单栏和分享编辑页面。(如果自定义这些UI可直接移除)
(c) PlatformSDK 第三方平台SDK。(不需要的平台的SDK可直接移除)

其中PlatformSDK文件夹下用来添加各个平台分享的sdk,可以根据需求下载。

2 将sdk导入工程

选中ShareSDK文件夹向工程中拖拽,拖到工程中后弹出以下对话框,勾选"Copy items into destination group's folder(if needed)",并点击“Finish“按钮, 如图

注意:请务必在上述步骤中选择“Create groups for any added folders”单选按钮组。如果你选择“Create folder references for any added folders”,一个蓝色的文件夹引用将被添加到项目并且将无法找到它的资源。

3 添加依赖库

如下图:3是Build phases。 4 是Link Binary With Libraries。

必须添加的依赖库如下(Xcode 7 下 *.dylib库后缀名更改为*.tbd):
  • SystemConfiguration.framework
  • QuartzCore.framework
  • CoreTelephony.framework
  • libicucore.dylib
  • libz.1.2.5.dylib
  • Security.framework
  • JavaScriptCore.framework
  • libstdc++.dylib
  • CoreText.framework
以下依赖库根据社交平台添加: 微信SDK依赖库   libsqkute3.dylib

设置appKey

打开AppDelegate.m文件。 导入头文件
#import <ShareSDK/ShareSDK.h>
#import "WXApi.h"
实现代理

@interface GAShareUtil ()<WXApiDelegate>

@end

在- (BOOL)application: didFinishLaunchingWithOptions:方法中调用registerApp方法来初始化SDK并且初始化第三方平台
/***  设置ShareSDK的appKey,如果尚未在ShareSDK官网注册过App,请移步到http://mob.com/login 登录后台进行应用注册*  在将生成的AppKey传入到此方法中。*  方法中的第二个第三个参数为需要连接社交平台SDK时触发,*  在此事件中写入连接代码。第四个参数则为配置本地社交平台时触发,根据返回的平台类型来配置平台信息。*  如果您使用的时服务端托管平台信息时,第二、四项参数可以传入nil,第三项参数则根据服务端托管平台来决定要连接的社交SDK。*/[ShareSDK registerApp:@"iosv1101"activePlatforms:@[@(SSDKPlatformTypeWechat)]onImport:^(SSDKPlatformType platformType){switch (platformType){case SSDKPlatformTypeWechat:[ShareSDKConnector connectWeChat:[WXApi class]delegate:self];break;case SSDKPlatformTypeQQ:[ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];break;case SSDKPlatformTypeSinaWeibo:[ShareSDKConnector connectWeibo:[WeiboSDK class]];break;default:break;}} onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo){switch (platformType){
//                        case SSDKPlatformTypeSinaWeibo:
//                             //设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权
//                            [appInfo SSDKSetupSinaWeiboByAppKey:@""
//                                                      appSecret:@""
//                                                    redirectUri:@""
//                                                       authType:SSDKAuthTypeBoth];
//                             break;case SSDKPlatformTypeWechat:[appInfo SSDKSetupWeChatByAppId:@""appSecret:@""];break;  default: break; 
} }];

然后打开下图位置,在URL Types中添加微信AppID   55BDA8FD-90BF-472B-999C-4C57680AB210

分享代码

1 简单分享 --无UI分享

/***  简单分享*/
- (void)simplyShare{/*** 在简单分享中,只要设置共有分享参数即可分享到任意的社交平台(前提是在AppDelegate中成功注册)**/__weak SHWeiXinViewController *theController = self;[self showLoadingView:YES];//创建分享参数NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];//可以是单张图片也可以是多张。NSArray* imageArray = @[[UIImage imageNamed:@"shareImg.png"]];if (imageArray) {[shareParams SSDKSetupShareParamsByText:@"分享内容"images:imageArrayurl:[NSURL URLWithString:@"http://www.mob.com"]title:@"分享标题"type:SSDKContentTypeAuto];//进行分享[ShareSDK share:SSDKPlatformSubTypeWechatSessionparameters:shareParams
//        [ShareSDK share:SSDKPlatformTypeSinaWeibo
//             parameters:shareParamsonStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {[theController showLoadingView:NO];[theController.wxtableView reloadData];switch (state) {//判断分享是否成功case SSDKResponseStateSuccess:{UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"message:nildelegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil];[alertView show];break;}case SSDKResponseStateFail:{UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享失败"message:[NSString stringWithFormat:@"%@", error]delegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil];[alertView show];break;}case SSDKResponseStateCancel:{UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享已取消"message:nildelegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil];[alertView show];break;}default:break;}}];}
}

/**

 * 设置分享参数

 *  @param text     文本

 *  @param images   图片集合,传入参数可以为单张图片信息,也可以为一个NSArray,数组元素可以为UIImageNSString(图片路径)、NSURL(图片路径)、SSDKImage。如: @"http://www.mob.com/images/logo_black.png"@[@"http://www.mob.com/images/logo_black.png"]

 *  @param url      网页路径/应用路径

 *  @param title    标题

 *  @param type     分享类型

 */

- (void)SSDKSetupShareParamsByText:(NSString *)text

                            images:(id)images

                               url:(NSURL *)url

                             title:(NSString *)title

                              type:(SSDKContentType)type;

SSDKContentType 用来设置分享类型。如下图所示 相同代码,不同的类型对应不同效果

     


当SSDKContentType设置为SSDKContentTypeAuto会自动判断分享的类型,类显示不同的界面。

2 分享菜单

显示分享菜单
- (void)showShareActionSheet:(UIView *)view{/*** 在简单分享中,只要设置共有分享参数即可分享到任意的社交平台**/__weak SHWeiXinViewController *theController = self;//1、创建分享参数(必要)NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];NSArray* imageArray = @[[UIImage imageNamed:@"shareImg.png"]];[shareParams SSDKSetupShareParamsByText:@"分享内容"images:imageArrayurl:[NSURL URLWithString:@"http://www.mob.com"]title:@"分享标题"type:SSDKContentTypeAuto];//2、分享[ShareSDK showShareActionSheet:viewitems:nilshareParams:shareParamsonShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {switch (state) {case SSDKResponseStateBegin:{[theController showLoadingView:YES];break;}case SSDKResponseStateSuccess:{//Facebook Messenger、WhatsApp等平台捕获不到分享成功或失败的状态,最合适的方式就是对这些平台区别对待if (platformType == SSDKPlatformTypeFacebookMessenger){break;}UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"message:nildelegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil];[alertView show];break;}case SSDKResponseStateFail:{if (platformType == SSDKPlatformTypeSMS && [error code] == 201){UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"message:@"失败原因可能是:1、短信应用没有设置帐号;2、设备不支持短信应用;3、短信应用在iOS 7以上才能发送带附件的短信。"delegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil, nil];[alert show];break;}else if(platformType == SSDKPlatformTypeMail && [error code] == 201){UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"message:@"失败原因可能是:1、邮件应用没有设置帐号;2、设备不支持邮件应用;"delegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil, nil];[alert show];break;}else{UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"message:[NSString stringWithFormat:@"%@",error]delegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil, nil];[alert show];break;}break;}case SSDKResponseStateCancel:{UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享已取消"message:nildelegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil];[alertView show];break;}default:break;}if (state != SSDKResponseStateBegin){[theController showLoadingView:NO];[theController.wxtableView reloadData];}                  }];   
}


显示分享菜单的方法

+ (SSUIShareActionSheetController *)showShareActionSheet:(UIView *)viewitems:(NSArray *)itemsshareParams:(NSMutableDictionary *)shareParamsonShareStateChanged:(SSUIShareStateChangedHandler)shareStateChangedHandler;

当items参数为nil时,则会 显示已集成的平台列表,可以通过设置items只显示自己需要的平台。 其中SSDKPlatformTypeWechat默认包括微信好友,朋友圈和微信收藏。可以通过设置这三个参数可以让各别显示和隐藏。

SSDKPlatformSubTypeWechatSession,SSDKPlatformSubTypeWechatTimeline,SSDKPlatformSubTypeWechatFav


[ShareSDK showShareActionSheet:nil//将要自定义顺序的平台传入items参数中items:@[@(SSDKPlatformTypeWechatTimeLine)@(SSDKPlatformTypeWechatSession)] shareParams:shareParams onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) { .......}];

效果图所示:

3 自定义分享菜单栏样式

// 弹出分享菜单需要导入的头文件
#import <ShareSDKUI/ShareSDK+SSUI.h>
// 自定义分享菜单栏需要导入的头文件
#import <ShareSDKUI/SSUIShareActionSheetStyle.h>//1、创建分享参数(必要)NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];NSArray* imageArray = @[[UIImage imageNamed:@"shareImg.png"]];(注意:图片要在Xcode左边目录里面,名称必须要传正确,或者是本地沙盒中的文件,如果要分享网络图片,可以这样传iamge参数 images:@[@"http://mob.com/Assets/images/logo.png?v=20150320"])[shareParams SSDKSetupShareParamsByText:@"分享内容"images:imageArrayurl:[NSURL URLWithString:@"http://mob.com"]title:@"分享标题"type:SSDKContentTypeAuto];// 设置分享菜单栏样式(非必要)// 设置分享菜单的背景颜色[SSUIShareActionSheetStyle setActionSheetBackgroundColor:[UIColor colorWithRed:249/255.0 green:0/255.0 blue:12/255.0 alpha:0.5]];// 设置分享菜单颜色[SSUIShareActionSheetStyle setActionSheetColor:[UIColor colorWithRed:21.0/255.0 green:21.0/255.0 blue:21.0/255.0 alpha:1.0]];// 设置分享菜单-取消按钮背景颜色[SSUIShareActionSheetStyle setCancelButtonBackgroundColor:[UIColor colorWithRed:21.0/255.0 green:21.0/255.0 blue:21.0/255.0 alpha:1.0]];// 设置分享菜单-取消按钮的文本颜色[SSUIShareActionSheetStyle setCancelButtonLabelColor:[UIColor yellowColor]];// 设置分享菜单-社交平台文本颜色[SSUIShareActionSheetStyle setItemNameColor:[UIColor redColor]];// 设置分享菜单-社交平台文本字体[SSUIShareActionSheetStyle setItemNameFont:[UIFont systemFontOfSize:11]];//2、弹出ShareSDK分享菜单[ShareSDK showShareActionSheet:viewitems:@[@(SSDKPlatformTypeWechatTimeLine)@(SSDKPlatformTypeWechatSession)]shareParams:shareParamsonShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) { ...... }
效果图:

4 跳过分享的编辑界面

弹出分享菜单,直接点击菜单中的平台分享(跳过分享的编辑界面)。

//先构造分享参数:NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];[shareParams SSDKSetupShareParamsByText:@"分享内容"images:@[[UIImage imageNamed:@"shareImg.png"]]url:[NSURL URLWithString:@"http://mob.com"]title:@"分享标题"type:SSDKContentTypeAuto];//调用分享的方法SSUIShareActionSheetController *sheet = [ShareSDK showShareActionSheet:viewitems:nilshareParams:shareParamsonShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {switch (state) {case SSDKResponseStateSuccess:NSLog(@"分享成功!");break;case SSDKResponseStateFail:NSLog(@"分享失败%@",error);break;case SSDKResponseStateCancel:NSLog(@"分享已取消");break;default:break;}}];//删除和添加平台示例[sheet.directSharePlatforms removeObject:@(SSDKPlatformTypeWechat)];
//(默认微信,QQ,QQ空间都是直接跳客户端分享,加了这个方法之后,可以跳分享编辑界面分享)[sheet.directSharePlatforms addObject:@(SSDKPlatformTypeSinaWeibo)];
//(其它平台默认会跳分享编辑界面,加了这个方法之后可以不跳分享编辑界面,直接点击分享菜单里的选项,直接分享)

5 不显示分享平台显示分享编辑菜单

[ShareSDK showShareEditor:SSDKPlatformTypeWechatotherPlatformTypes:@[@(SSDKPlatformTypeSinaWeibo),@(SSDKPlatformTypeTencentWeibo)]shareParams:shareParamsonShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end){}];


显示分享编辑框,只有微信,不显示otherPlatformTypes中的其它选项。



6 自定义编辑框

导入

#import <ShareSDK/ShareSDK.h>

#import <ShareSDKUI/SSUIEditorViewStyle.h>

NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];[shareParams SSDKSetupShareParamsByText:@"分享内容..."images:imageArrayurl:[NSURL URLWithString:@"http://mob.com"]title:@"分享标题"type:SSDKContentTypeImage];//自定义编辑区样式(非必要)//设置iPhone导航栏颜色[SSUIEditorViewStyle setiPhoneNavigationBarBackgroundColor:[UIColor redColor]];//设置编辑界面背景颜色[SSUIEditorViewStyle setContentViewBackgroundColor:[UIColor cyanColor]];//设置标题[SSUIEditorViewStyle setTitle:@"微信分享"];//设置取消按钮标签[SSUIEditorViewStyle setCancelButtonLabel:@"算了吧"];//设置取消按钮标签文本颜色[SSUIEditorViewStyle setCancelButtonLabelColor:[UIColor blackColor]];[ShareSDK showShareEditor:SSDKPlatformTypeWechatotherPlatformTypes:@[@(SSDKPlatformTypeSinaWeibo),@(SSDKPlatformTypeTencentWeibo)]shareParams:shareParamsonShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end){
}];


7 隐藏“微信收藏”平台

方法有两种

1 在appDeleagete中修改,这样比较方便。

[ShareSDK registerApp:@"XXXXXXX"activePlatforms:@[// 不要使用微信总平台进行初始化//@(SSDKPlatformTypeWechat),// 使用微信子平台进行初始化,即可@(SSDKPlatformSubTypeWechatSession),@(SSDKPlatformSubTypeWechatTimeline),]onImport:^(SSDKPlatformType platformType) {switch (platformType){case SSDKPlatformTypeWechat:[ShareSDKConnector connectWeChat:[WXApi class]];break;default:break;}}onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) {switch (platformType){case SSDKPlatformTypeWechat:[appInfo SSDKSetupWeChatByAppId:@"wx4868b35061f87885"appSecret:@"64020361b8ec4c99936c0e3999a9f249"];break;default:break;}}];

2 在某些使用的地方,将SSDKPlatformTypeWechat修改成微信子平台,去掉微信收藏。这个是针对个别地方隐藏。


8 平台内容定制

/*** 在定制平台内容分享中,除了设置共有的分享参数外,还可以为特定的社交平台进行内容定制,* 如:其他平台分享的内容为“分享内容”,但微信需要在原有的“分享内容”文字后面加入一条链接,则可以如下做法:**/__weak SHWeiXinViewController *theController = self;[theController showLoadingView:YES];//创建分享参数NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];NSArray* imageArray = @[[UIImage imageNamed:@"shareImg.png"]];if (imageArray) {[shareParams SSDKSetupShareParamsByText:@"分享内容"images:imageArrayurl:[NSURL URLWithString:@"http://mob.com"]title:@"分享标题"type:SSDKContentTypeImage];[shareParams SSDKSetupWeChatParamsByText:@"分享内容 http://mob.com"title:@"分享标题"url:[NSURL URLWithString:@"http://mob.com"]thumbImage:[UIImage imageNamed:@"shareImg.png"]image:[UIImage imageNamed:@"shareImg.png"]musicFileURL:nilextInfo:nilfileData:nilemoticonData:nilsourceFileExtension:nilsourceFileData:niltype:SSDKContentTypeAutoforPlatformSubType:SSDKPlatformSubTypeWechatSession];//进行分享[ShareSDK share:SSDKPlatformTypeWechatparameters:shareParamsonStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
}];


9 分享本地文件(mp3、mp4、docx、pdf等)


NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];UIImage *imageThumb = [UIImage imageNamed:@"Icon.png"];NSString *filePath = [[NSBundle mainBundle] pathForResource:@"cattest" ofType:@"mp4"];[shareParams SSDKSetupWeChatParamsByText:@"视频分享。。。"title:@"视频分享"url:nilthumbImage:imageThumbimage:imageThumbmusicFileURL:nilextInfo:nilfileData:nilemoticonData:nilsourceFileExtension:@"mp4"sourceFileData:filePathtype:SSDKContentTypeFileforPlatformSubType:SSDKPlatformSubTypeWechatSession];//进行分享[ShareSDK share:SSDKPlatformSubTypeWechatSessionparameters:shareParamsonStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
}];

分享文件时:

 *  设置typeSSDKContentTypeFile(例如.mp3.mp4.pdf.docx的分享),设置titlesourceFileExtensionsourceFileData,以及thumbImage参数,如果尚未设置thumbImage则会从image参数中读取图片并对图片进行缩放操作参数

 */

注意(分享失败的两个坑):文件大小不能超过10M,thumbImage图片大小不能超过32k,最好是宽高相等。


10 摇一摇分享

导包

#import <ShareSDK/ShareSDK.h>

#import <ShareSDKExtension/SSEShareHelper.h>

/*** 使用ShareSDKExtension插件可以实现摇一摇分享* 通过使用SSEShareHelper可以调用开启/结束摇一摇分享方法,在方法的onWillShareHandler参数中可以处理摇一摇后的分享处理操作。** 小技巧:* 当取得摇一摇事件通知后,如果shareHandler入口不满足分享需求(如需要弹出分享菜单而不是直接分享),可以不调用shareHandler进行分享,而是在block中写入自定义的分享操作。* 这样的话摇一摇分享接口实质只充当捕获摇一摇通知的功能。**/__weak SHWeiXinViewController *theController = self;//开启摇一摇分享功能[SSEShareHelper beginShakeShare:nilonEndSake:nilonWillShareHandler:^(SSEShareHandler shareHandler){NSLog(@"======开始分享");//构造分享参数NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];NSArray* imageArray = @[[UIImage imageNamed:@"shareImg.png"]];if (imageArray){[shareParams SSDKSetupShareParamsByText:@"摇着摇着就可以分享出去了,使用ShareSDK分享就是便捷方便。"images:imageArrayurl:niltitle:niltype:SSDKContentTypeImage];//显示等待界面[theController showLoadingView:YES];//回调分享if (shareHandler){shareHandler (SSDKPlatformTypeWechat, shareParams);}}}onStateChanged:^(SSDKResponseState state,NSDictionary *userData,SSDKContentEntity *contentEntity, NSError *error) {
}];

iOS 9 异常

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

问题描述:在iOS9下,系统默认会拦截对http协议接口的访问,因此无法获取http协议接口的数据。对ShareSDK来说,具体表现可能是,无法授权、分享、获取用户信息等。

还可能造成我们的编辑界面里传http之类的网络图片的时候,我们的编辑界面不会显示图片截图,解决的办法或者全面关闭https,允许使用http请求;或者把图片的域添加;又或者选择使用https的图片

解决方案(以下方法2选1):

(1)、暂时退回到http协议。

具体方法:

在项目的info.plist中添加一个Key:NSAppTransportSecurity,类型为字典类型。

然后给它添加一个Key:NSAllowsArbitraryLoads,类型为Boolean类型,值为YES;

751FEFB8-86A2-45EC-8F61-A1A5081C5465

(2)http://wiki.mob.com/ios9-对sharesdk的影响(适配ios-9必读)/


demo下载地址


http://chatgpt.dhexx.cn/article/5qtG719v.shtml

相关文章

微信分享功能

最近在做手机端页面&#xff0c;需要一个分享功能&#xff0c;其实自身分享是可以的&#xff0c;但是为了分享出的内容丰富&#xff0c;比如缩略图了&#xff0c;描述了等等&#xff0c;如下图所示&#xff1a; 步骤一&#xff1a;绑定域名 先登录微信公众平台进入“公众号…

Android app分享文件到微信

两种实现方案&#xff1a; 1.使用WXFileObject构造分享方法发送到微信&#xff1b; 2.调用系统分享方法&#xff0c;把文件直接发送到微信&#xff1b; 那么下面来分别看看怎么实现&#xff1a; 〇、准备工作 首先&#xff0c;需要在AndroidManifest.xml中配置FileProvider信…

ShareSDK关于微信分享问题

转自&#xff1a;http://www.eoeandroid.com/thread-310281-1-1.html 发现用sharesdk&#xff0c;做其他平台分享很快&#xff1b;如新浪微博、腾讯微博、有道云笔记、开心网、Google等等&#xff0c;几句代码就搞定&#xff1b; 但是微信有点麻烦&#xff0c;下面我把…

uniapp实现录音喊话功能

直接先上代码&#xff1a; const recorderManager uni.getRecorderManager() onShow() {this.test()},methods: {test() {uni.getSetting({success: (res) > {console.log(res.authSetting, res.authSetting[scope.record]);if (res.authSetting[scope.record] false) {…

h5调用android录音,html5网页录音插件Recorder

插件描述&#xff1a;html5 js 录音 mp3 wav ogg webm amr 格式&#xff0c;支持pc和Android、ios部分浏览器、和Hybrid App(提供Android IOS App源码)&#xff0c;微信也是支持的&#xff0c;提供H5版语音通话聊天示例 Recorder用于html5录音 支持大部分已实现getUserMedia的移…

利用RecordRTC.js实现H5录音功能

前言&#xff1a; 最近遇到 要语音转文字 的需求&#xff0c;语音转文字肯定要先搞定录音功能&#xff0c;在网上找了好久没找到具体的 RecordRTC.js 插件的使用方法&#xff0c;最后只能对着 github 上开源代码小试了一下&#xff0c;录音功能好使所以就记录一下叭 一、Reco…

vue录音+js-audio-recorder

小小记录一下项目中用到的录音功能 1.下载插件 npm i js-audio-recorder 2.展示代码 <template><div style"padding: 20px;"><div style"font-size:14px"><h3>录音时长&#xff1a;{{ recorder && recorder.duration.…

html 苹果微信录音js,微信js-sdk 录音功能的示例代码

需求描述 制作一个H5页面&#xff0c;打开之后可以录音&#xff0c;并将录音文件提交至后台 微信录音最长时长为1min 代码如下 // isVoice&#xff1a; 0-未录音 1-录音中 2-录完音 // 点击录音/录音中 按钮展示 点击录音 // isListen // 0-未试听/试听结束 1-试听中 2-暂停试听…

已解决:H5移动端网页实现录音功能,js实现录音功能,包括安卓webview接口也可以使用

遇到一个需求&#xff0c;需要做一个手机网页录音的功能&#xff0c;嵌入到webview中去&#xff0c;用安卓原生录音倒是可以&#xff0c;但是想着尽量去安卓化开发&#xff0c;就想着用纯的js前端代码去实现录音功能。 在 Web 应用程序中&#xff0c;JavaScript 是运行在浏览器…

网页录音时的麦克风权限问题解决

来源 | https://www.html.cn/web/html/19184.html 在我们进行网页制作时可能会遇到需要录音的情况&#xff0c;而在进行网页录音时又有可能会遇到麦克风权限问题导致无法录音&#xff0c;本文就来为大家介绍一下如何解决麦克风权限问题。 在本地中打开的时候&#xff0c;谷歌、…

获取摄像头和麦克风权限_js获取浏览器摄像头和麦克风权限

前言 项目中会使用到摄像头或麦克风设备&#xff0c;这就需要我们获取浏览器的摄像头和麦克风权限&#xff0c;权限是无法通过js操控的&#xff0c;必须由浏览器用户设置。 下面我来告诉大家如何获取浏览器的摄像头或麦克风的权限&#xff0c;使浏览器弹出询问窗口。 一、我们想…

(前端)录音功能实现 js-audio-recorder

1. 创建 import Recorder from js-audio-recorder const parameter {sampleBits: 16, // 采样位数&#xff0c;支持 8 或 16&#xff0c;默认是16sampleRate: 8000, // 采样率&#xff0c;支持 11025、16000、22050、24000、44100、48000&#xff0c;根据浏览器默认值&#x…

Android webview录音权限和音频自动播放

项目背景&#xff1a;我们通过layabox&#xff0c;制作了H5页面&#xff0c;可以在微信中&#xff0c;手机浏览器中使用&#xff0c;现在需要将H5页面集成到Android的APP中。 遇到的问题&#xff1a; 1.遇到的第一个问题&#xff0c;是获取录音权限的问题&#xff0c;我已经给…

html 苹果微信录音js,基于JS开发微信网页录音功能的实例代码

具体代码如下所示&#xff1a; wx.ready(function () { var startRecordflag false var startTime null //btnRecord 为录音按钮dom对象 btnRecord.addEventListener(touchstart, function (event) { event.preventDefault(); startTime newDate().getTime(); // 延时后录音…

std::string 与 std::wstring 互转

前言: 最近接触了一些 win32 方便的编程,由于不熟 可能会写一写这方便的基础东西 相当于 写日记了 提升一下 他们的声明 string 是 char wstring 是wchar_t 什么是wchar_t ? string 转 wstring inline std::wstring StringToWString(const std::string& str) {int len…

C++ 字符串string、字符char、宽字符数组wstring、宽字符wchar_t互相转换(2021.4.20)

C单字符串和宽字符串学习 2021.4.20 1、char 和 string1.1 单字符 char1.2 单字符数组 char[] 和 char*1.2.1 char[]1.2.2 char* 1.3 单字符串 string1.4 char[] 转 string1.5 cha[] 转char*1.6 string 转 char*1.7 string 转 char[] 2、wchar_t 和 wstring2.1 宽字符 wchar_t2…

string和wstring相互转换以及wstring显示中文问题

如果你只是使用C来处理字符串&#xff0c;会用到string。不过string是窄字符串ASCII&#xff0c;而很多Windows API函数用的是宽字符Unicode。这样让string难以应对。作为中国的程序员&#xff0c;我们第一个想到的字符串就是中文&#xff0c;而不是英文。所以经常会遇到中文字…

C++里面,什么时候使用std::wstring

看你要使用什么字符编码了&#xff0c; std::wstring主要用于 UTF-16编码的字符,而std::string主要用于存储单字节的字符( ASCII字符集 )&#xff0c;但是也可以用来保存UTF-8编码的字符。&#xff08;UTF-8和UTF-16是UNICODE字符集的两种不同的字符编码&#xff09; 如果你的…

String类与wstring类的区别

String类与wstring类的区别 本质区别 存储字符的区别 #include <iostream> #include <string> using namespace std; int main() { wstring wstr1 L"你好世界"; // L普通字符串 宽字符串 const wchar_t *ch1 wstr1.c_str(); // 转化为宽字符…

从新建工程开始使用C++开发单片机(以STM32为例):七、移植Arduino的WString(附代码)

在上一篇文章中&#xff0c;介绍了outputString和inputString&#xff0c;其中所运用到的字符串类型String也是C驱动层中功能强大且重要的一个类。这个类移植自Arduino的WString。这篇文章将会展示WString的易用性&#xff0c;并且从编译输出后程序大小的角度比较WSting和C std…