1. TARGETS - Info - URL Types

identifier -> weixin

URL Schemes -> 应用id

2.在AppDelegate.h 引入头文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<pre name="code" >#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];
}
 
 
-(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];
}

微信分享 添加URL Schemes的更多相关文章

  1. iOS9适配 之 关于info.plist 第三方登录 添加URL Schemes白名单

    近期苹果公司iOS 9系统策略更新,限制了http协议的访问,此外应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装. 受此影响,当你的应用在 ...

  2. LSApplicationQueriesSchemes--关于info.plist 第三方登录 添加URL Schemes白名单

    近期苹果公司iOS 9系统策略更新,限制了http协议的访问,此外应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装. 当你的应用在iOS 9 ...

  3. 【转】iOS9适配 之 关于info.plist 第三方登录 添加URL Schemes白名单

    近期苹果公司iOS 9系统策略更新,限制了http协议的访问,此外应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装. 受此影响,当你的应用在 ...

  4. Swift URL Schemes使用

    URL Schemes通常用于分享和第三方登录,但有时需要在html跳至APP,或者APP跳至另外一个APP.这时也需要使用URL Schemes. 一.html跳转至APP eg:html跳转至te ...

  5. WKWebView无法(通过URL schemes)跳转到其他App

    Custom scheme URL 在WKWebView中默认是不支持的 (但Safari可以). 我们可以通过NSError来进行一些处理从而使得程序可以正常跳转: func webView(web ...

  6. iOS 之URL schemes

    添加 URL  schemes 步骤: 1.打开info.plist文件. 2.点击 “+ ”号添加,或者在列表上点击鼠标右键,选择 Add Row. 3.选择 URL types. 4.点击三角号展 ...

  7. iOS 微信打开第三方应用(Universal Links 和 URL Schemes)

    一.前言 项目中时常有这种需求, 是通过链接跳转到应用内部,现在iOS主流的方案有两个 Schema: 常用在于一个应用跳转到另一个应用内部,属于应用间的跳转.当然ios9以下,网页可以通过schem ...

  8. 微信分享功能引入页面-控制分享时候调用的标题、图片、url和微信按钮隐藏显示控制

    1.设置分享调用的标题.图片.url预览. 2.控制右上角三个点按钮的隐藏显示(和底部工具栏的显示隐藏--未测试). 3.判断网页是否在微信中被调用. <!doctype html> &l ...

  9. vue微信分享链接添加动态参数

    微信分享时 分享链接携带参数可能不是固定的 需要在分享的前一刻才知道 这里就是动态设置分享链接的基本写法 代码不是那么详尽 但大致流程如下 1.安装引用jssdk npm install --save ...

随机推荐

  1. Qt之Concurrent Map和Map-Reduce

    简述 QtConcurrent::map().QtConcurrent::mapped()和QtConcurrent::mappedReduced()函数在一个序列中(例如:QList或QVector ...

  2. HDU----(3294)Girls' research(manacher)

    Girls' research Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)T ...

  3. IO流--复制picture ,mp3

    import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import ...

  4. SO修改

    FUNCTION Z_SD_SALESORDER_CHANGE1. *"----------------------------------------------------------- ...

  5. 【转载】JSP中文乱码问题

     原作者http://www.cnblogs.com/xing901022/p/4354529.html 阅读目录 之前总是碰到JSP页面乱码的问题,每次都是现在网上搜,然后胡乱改,改完也不明白原因. ...

  6. 一份C++线程池的代码,非常实用

    #ifndef _ThreadPool_H_ #define _ThreadPool_H_ #pragma warning(disable: 4530) #pragma warning(disable ...

  7. 一年成为Emacs高手(像神一样使用编辑器)

    作者: 陈斌(redguardtoo) 版本号: 20150424 更新时间: <2015-04-24 Fri> 原创时间: <2012-01-31 Tue> 版权: 本文采用 ...

  8. PHP/MYSQL 查询大数据/遍历表

    PHP:PHP 5.3.6 (cli) (built: Jun 15 2011 16:29:50) MYSQL:5.1.51 如果我们有的一张表有几百万或几千万的记录,我们要使用 PHP 将所有的记录 ...

  9. 使用SMSManager短信管理器发送短信

    import android.os.Bundle;import android.app.Activity;import android.app.PendingIntent;import android ...

  10. plsql记住登录密码

    登录plsql:tools(工具)->preference(首选项)->Login history(登录历史):选择"Store with password"(带口令存 ...