微信分享

依赖库
在这里插入图片描述

在这里插入图片描述
-Objc
-all_load

导入微信SDK

app.h

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

@property (strong, nonatomic) UIWindow *window;


@end

app.m

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (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];
    
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end

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

info
在这里插入图片描述

LSApplicationQueriesSchemes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值