ios 微信开发

首先依照对应的文档获得对应的key 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [WXApi registerApp:@"wxd930ea5d5a258f4f" withDescription:@"demo 2.0"];
    return YES;
}

  然后配置对应的url  types

ios  微信开发

注冊想你得到的appkey

     之后在点击分享的target事件中加入须要的分享信息和链接

           if ( [WXApi isWXAppInstalled]) {//isWXAppInstalled推断是否手机上面有微信
    // 读取图片
    NSData  *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];
    UIImage *imageNew=[UIImage imageWithData:data];
    if (!data || [imageUrl isEqualToString:@""]||!imageUrl) {
        imageNew = [UIImage imageNamed:@"AM_Logo_Share"];
    }
    imageNew = [self scaleToSize:imageNew size:CGSizeMake(imageNew.size.width*0.9, imageNew.size.height*0.9)];
    data= UIImageJPEGRepresentation(imageNew,1);//调整图片大小的,这个是自己的图片有些大
    if ([data length]> 30*1024) {
        data= UIImageJPEGRepresentation(imageNew,0.1);
    }
    WXMediaMessage *message = [WXMediaMessage message];
    message.title = title;                      分享的tittle
    message.description =des;            分享的详情
    [message setThumbData:data];     分享的图片
    
    WXWebpageObject *ext = [WXWebpageObject object];
    ext.webpageUrl = link;                link是分享的链接
    
    message.mediaObject = ext;
    SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    req.message = message;
    if (type == WeiXin) { //微信好友               推断是分享到朋友圈还是分享到好友
        req.scene = WXSceneSession;
    }else if (type == WXFriends){//朋友圈
        req.scene = WXSceneTimeline;
    }else{
        
    }
    
    [WXApi sendReq:req];
    
}else{
    NSLog(@"还没安装微信");  //以下的是,假设没有微信,提示下在微信或者取消
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您还没有安装微信" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"下载安装微信", nil];
    [alertView show];
 }
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex) {
        case 0:
            
            break;
        case 1:
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[WXApi getWXAppInstallUrl]]];
            break;
        default:
            break;
    }
}

//这是自己调整图片大小的方法
- (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
    UIGraphicsBeginImageContext(size);
    [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}
之后还要跳转对应第三方app的处理

 在APPdelegate里面增加两个方法

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{

//凝视的是假设有多个分享,比方qq ,微博等   而WeChatKey,SinaKey 这些是对应的请求得到的appkey

//    if([url.scheme isEqualToString:WeChatKey])
//    {
//        return [WXApi handleOpenURL:url delegate:self];
//    }else if([url.scheme isEqualToString:[NSString stringWithFormat:@"wb%@",SinaKey]])
//    {
//        return [WeiboSDK handleOpenURL:url delegate:self];
//        
//    }else
//    {
//        return [TencentOAuth HandleOpenURL:url];
//    }
    return  [WXApi handleOpenURL:url delegate:self];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    BOOL isSuc = [WXApi handleOpenURL:url delegate:self];
    return  isSuc;
}


假设要知道你分享的成功和失败,则须要调用

-(void) onReq:(BaseReq*)req
{

}


-(void) onResp:(BaseResp*)resp
{

}

这两个方法,在这两个方法内做对应的处理

   


ios 微信开发

上一篇:微信公众号可快速创建“门店小程序” 不用开发


下一篇:微信小程序学习笔记--20170425--登录验证实现