微信分享

1.在这里插入图片描述

2.-Objc
-all_load
在这里插入图片描述
4.
导入微信SDK
app.h

#import “WeChatSDK1.8.3_NoPay/WXApi.h”
@interface AppDelegate : UIResponder <UIApplicationDelegate , WXApiDelegate>

5.app.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    // 向微信注册
    [WXApi registerApp:@"wx537cf8aac45b25df"];
    
    return YES;
}


// 重写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];
    
}

7.vc.m

#import "ViewController.h"
#import "WeChatSDK1.8.3_NoPay/WXApi.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    

    
    
    UIImageView *imgV = [[UIImageView alloc]initWithFrame:self.view.frame];
    imgV.image = [UIImage imageNamed:@"444"];
    [self.view addSubview:imgV];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 300, 100, 50)];
    [btn setTitle:@"图片分享" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor purpleColor];
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = [UIColor greenColor].CGColor;
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    
    UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(250, 300, 100, 50)];
    [btn1 setTitle:@"文字分享" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    btn1.backgroundColor = [UIColor purpleColor];
    btn1.layer.borderWidth = 1;
    btn1.layer.borderColor = [UIColor greenColor].CGColor;
    [btn1 addTarget:self action:@selector(press) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];
    
    
}
// 图片分享
-(void)click{
    
    WXMediaMessage *message = [WXMediaMessage message];
    [message setThumbImage:[UIImage imageNamed:@"222"]];
    // 缩略图
    WXImageObject *imageobject = [WXImageObject object];
    //    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"resl" ofType:@"png"];
    imageobject.imageData = UIImagePNGRepresentation( [UIImage imageNamed:@"222"]);
    message.mediaObject = imageobject;
    
    
    SendMessageToWXReq *req1 = [[SendMessageToWXReq alloc]init];
    req1.bText = NO;
    req1.message = message;
    req1.scene = WXSceneTimeline;// 分享到朋友圈
    [WXApi sendReq:req1];
    
}
// 文字分享
-(void)press{
    
        SendMessageToWXReq *req = [[SendMessageToWXReq alloc]init];
        req.text = @"可不可以,允许我,任性一次。不为未来,只为这即将离开的青春年少。可不可以,允许我,任性一次。只带本心,抛下一切的枷锁负担去飞翔。可不可以,允许我,任性一次。还在年少,总要疯狂叛逆一次不问后果";
        req.bText = YES;
        req.scene = WXSceneSession;
        [WXApi sendReq:req];
    
}


@end


8.LSApplicationQueriesSchemes
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值