iOS - 社会化分享-微信分享,朋友圈分享
我仅仅做了文字和图片分享功能
1. TARGETS - Info - URL Types
identifier -> weixin
URL Schemes -> 应用id
2.在AppDelegate.h 引入头文件
#import "WXApi.h"
{
/**
* WXSceneSession 分享到会话
* WXSceneTimeline 分享到朋友圈
* WXSceneFavorite 分享到我的收藏
*/
enum WXScene _scene;
}
- (id)init
{
if(self = [super init]){
_scene = WXSceneSession;
}
return self;
}
-(void) changeScene:(NSInteger)scene
{
_scene = scene;
} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ // 其他代码 // 向微信注冊应用ID
[WXApi registerApp:@"xxooxoxoxoxoxoxo"];
} #pragma mark - 重写AppDelegate的handleOpenURL和openURL方法
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
//假设应用还有其他社会化分享,需在此处加推断
return [WXApi handleOpenURL:url delegate:self];
} - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [WXApi handleOpenURL:url delegate:self];
}
onReq 和 onResp 能够不写
-(void) onReq:(BaseReq*)req
{
if([req isKindOfClass:[GetMessageFromWXReq class]])
{
// 微信请求App提供内容, 须要app提供内容后使用sendRsp返回
NSString *strTitle = [NSString stringWithFormat:@"微信请求App提供内容"];
NSString *strMsg = @"微信请求App提供内容,App要调用sendResp:GetMessageFromWXResp返回给微信"; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
alert.tag = 1000;
[alert show];
[alert release];
}
else if([req isKindOfClass:[ShowMessageFromWXReq class]])
{
ShowMessageFromWXReq* temp = (ShowMessageFromWXReq*)req;
WXMediaMessage *msg = temp.message; //显示微信传过来的内容
WXAppExtendObject *obj = msg.mediaObject; NSString *strTitle = [NSString stringWithFormat:@"微信请求App显示内容"];
NSString *strMsg = [NSString stringWithFormat:@"标题:%@ \n内容:%@ \n附带信息:%@ \n缩略图:%u bytes\n\n", msg.title, msg.description, obj.extInfo, msg.thumbData.length]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
else if([req isKindOfClass:[LaunchFromWXReq class]])
{
//从微信启动App
NSString *strTitle = [NSString stringWithFormat:@"从微信启动"];
NSString *strMsg = @"这是从微信启动的消息"; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
} -(void) onResp:(BaseResp*)resp
{
if([resp isKindOfClass:[SendMessageToWXResp class]])
{
NSString *strTitle = [NSString stringWithFormat:@"发送媒体消息结果"];
NSString *strMsg = [NSString stringWithFormat:@"errcode:%d", resp.errCode]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
}
4.这是我写好的在微信会话和朋友圈分享文字或者图片的方法
直接调用就能够, 也能够按需求整到一起
#pragma mark - 微信, 朋友圈分享
#pragma mark 文字分享
- (void)sharedByWeChatWithText:(NSString *)WeChatMessage sceneType:(int)sceneType
{
SendMessageToWXReq *req = [[[SendMessageToWXReq alloc] init]autorelease];
req.text = WeChatMessage;
req.bText = YES;
req.scene = sceneType;
[WXApi sendReq:req];
} #pragma mark 图片分享
- (void)sharedByWeChatWithImage:(NSString *)imageName sceneType:(int)sceneType
{
WXMediaMessage *message = [WXMediaMessage message];
[message setThumbImage:[UIImage imageNamed:imageName]]; WXImageObject *ext = [WXImageObject object];
NSString *filePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
ext.imageData = [NSData dataWithContentsOfFile:filePath];
UIImage *image = [UIImage imageWithData:ext.imageData];
ext.imageData = UIImagePNGRepresentation(image); message.mediaObject = ext; SendMessageToWXReq *req = [[[SendMessageToWXReq alloc] init]autorelease];
req.bText = NO;
req.message = message;
req.scene = sceneType; [WXApi sendReq:req];
}
iOS - 社会化分享-微信分享,朋友圈分享的更多相关文章
- Android 分享微信好友 朋友圈
第三方应用,可以调用微信分享,把链接,文字,各种media,分享到微信好友或者微信朋友圈,步骤: package com.edaixi.utils; import android.content.Co ...
- React Native微信分享 朋友圈分享 Android/iOS 通用
超详细React Native实现微信好友/朋友圈分享功能-Android/iOS双平台通用 2016/06/16 | React Native技术文章 | Sky丶清| 暂无评论 | 1 ...
- 微信 6.5.1 for iOS发布 可以在朋友圈分享相册中的视频
今天微信 6.5.1 for iOS发布了,最主要的一个功能是可以在朋友圈分享相册中的视频,卖转发朋友圈视频软件的家伙估计要哭了.微信这次更新,更有利于个人号的运营,个人号的价值将更高.先定一个小目标 ...
- H5+ 分享到微信、朋友圈代码示例
h5+分享到微信.朋友圈代码示例 在使用分享功能的时候会莫名的分享失败,debug时发现是图片过大的问题. 图片过大时ios平台上返回错误码-8,安卓上返回错误码-3(我测试是这样) 因此如果第一次分 ...
- 纯Java实现微信朋友圈分享图
纯Java实现微信朋友圈分享图 1.实现分享图的效果 2.开发环境 2.1 JDK * oracle's jdk 1.8以上 2.2 字体 * 若选择了微软雅黑字体又是代码部署到Linux,则需要安装 ...
- ionic 实现微信朋友圈分享的完整开发流程
最近开始要着手负责开发ionic的项目了,一直很好奇想实现一个微信朋友圈分享的功能,所以我就网上找了找文章来练手实现,果不其然,找到了几篇,但是发现它们的流程都不太详细,清楚,直接,还有不少坑. 今天 ...
- apiCloud 三方分享,微信好友分享,微信朋友圈分享,QQ分享,微博分享
首先查看我的这篇有关三方登录的博客,地址是http://www.cnblogs.com/gqx-html/p/8303567.html,配置完三方数据后可以从上一篇文章中的链接跳转到各个登录查看api ...
- Android分享到微信和朋友圈的工具类
1.只要填写上正确的app_id,且引用上该工具类你就能实现分享到朋友圈和分享到微信. 2.需要到微信平台下载jar包,以及注册一个appid import android.content.Conte ...
- 微信分享缩略图,如何增加微信朋友圈分享链接的小图片? facebook、google+、twitter等分享的标签
微信分享缩略图 如何增加微信朋友圈分享链接的小图片?在网页的头部<head>标签内加上以下代码,图片路径自行修改.<head><div id='wx_pic' style ...
随机推荐
- Sybase_ASA 字符串拼接
列转行并拼接字符串,使用LIST函数 SELECT LIST(T.NAME,',') FROM TAB_DEMO T;
- 零基础学习Python培训,应该选择哪个培训班?
近几年中,Python一直是市场上最受欢迎的编程语言之一.它语法自然,入门简单,同时应用范围又极广,无论是大火的人工智能.大数据还是传统的web开发.自动化运维,Python都能够大展拳脚.根据职友集 ...
- 转:LINQ教程一:LINQ简介
原文地址:https://www.cnblogs.com/dotnet261010/p/8278793.html 一.为什么要使用LINQ 要理解为什么使用LINQ,先来看下面一个例子.假设有一个整数 ...
- 集成学习_Bagging 和随机森林(rf)
集成学习方式总共有3种:bagging-(RF).boosting-(GBDT/Adaboost/XGBOOST).stacking 下面将对Bagging 进行介绍:(如下图所示) ...
- Oracle数据库的自动备份脚本
@echo off echo ================================================ echo Windows环境下Oracle数据库的自动备份脚本 echo ...
- mapbox-gl 使用ArcGISServer 发布的栅格切片
最近使用mapbox 进行数据化展现.刚好用到了超图平台在去三维系统,顺带就用超图平台发布了栅格切片,用来做底图,但是超图平台是试用的许可,栅格切片有SuperMap 的水印,实在不雅观. 在网上搜索 ...
- P2884 [USACO07MAR]每月的费用Monthly Expense
题目描述 Farmer John is an astounding accounting wizard and has realized he might run out of money to ru ...
- Scrapy爬虫框架示意图汇总
- 00.不规则json序列化使用eval、demjson
有下面一段字符串 import json str0 = '[{"name":"白云大道营业厅","siteaddr":"x...& ...
- 303. Range Sum Query - Immutable(动态规划)
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...