iOS新浪微博 微信好友、微信朋友圈、QQ自身sdk分享方法

sina微博

WBMessageObject *message = [WBMessageObject message];

        WBWebpageObject *webpage = [WBWebpageObject object];
        webpage.objectID = @"identifier1";
        if (self.shareTitle != nil || self.shareStr != nil) {
            webpage.title = self.shareTitle;
            webpage.description = self.shareStr;//NSLocalizedString(@"副标题-%.0f", nil), [[NSDate date] timeIntervalSince1970]
        }else {
            webpage.title = @"啊啊啊";
            webpage.description = @"小伙伴快来下载   App吧";
        }
        
        if (self.shareImage != nil) {
            UIImageView *shareImageView = [[UIImageView alloc] init];
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                [shareImageView hr_setImageWithObjectKey:self.shareImage placeholderImage:nil options:(HRImageContentTypeWEBP) completed:^(UIImage *image, NSError *error) {
                    shareImageView.image = image;
                }];
            });
            webpage.thumbnailData = UIImagePNGRepresentation(shareImageView.image);
        }else {
            webpage.thumbnailData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"shareIcon@2x" ofType:@"png"]];
        }
        
        webpage.webpageUrl = @"http://hiroad-share.hi-road.com/share/fenxiang.html";
        message.mediaObject = webpage;

        //send
        WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message];
        request.userInfo = @{@"ShareMessageFrom": @"SendMessageToWeiboViewController",
                             @"Other_Info_1": [NSNumber numberWithInt:123],
                             @"Other_Info_2": @[@"obj1", @"obj2"],
                             @"Other_Info_3": @{@"key1": @"obj1", @"key2": @"obj2"}};
        request.shouldOpenWeiboAppInstallPageIfNotInstalled = NO;
        [WeiboSDK sendRequest:request];




微信好友


//    if ([WXApi isWXAppInstalled] == 1) {
//        SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
//        sendReq.bText = NO;
//        sendReq.scene = 1;
//        WXMediaMessage *urlMessage = [WXMediaMessage message];
//        if (self.shareStr != nil) {
//            urlMessage.title = [NSString stringWithFormat:@"%@ %@",self.shareTitle ,self.shareStr];
//        }else {
//            urlMessage.title = @"下";//标题
//        }
////            urlMessage.description = @"副标题";
//        
//        //    if (self.shareImage != nil) {
//        //        UIImageView *shareImageView = [[UIImageView alloc] init];
//        //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//        //            [shareImageView hr_setImageWithObjectKey:self.shareImage placeholderImage:nil options:(HRImageContentTypeWEBP) completed:^(UIImage *image, NSError *error) {
//        //                shareImageView.image = image;
//        //
//        //            }];
//        //        });
//        //        UIImage *image = shareImageView.image;
//        //        NSData *photo = UIImageJPEGRepresentation(image, 0.4);
//        //        [urlMessage setThumbImage:[UIImage imageWithData:photo]];
//        //    }else {
//        UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithContentsOfURL:[self shareImageUrl] encoding:(NSUTF8StringEncoding) error:nil]];
//        [urlMessage setThumbImage:image];
//        //    }
//        
//        WXWebpageObject *webObj = [WXWebpageObject object];
//    
//        webObj.webpageUrl = [self shareUrl];
//      
//        
//        urlMessage.mediaObject = webObj;
//        sendReq.message = urlMessage;
//        
//        [WXApi sendReq:sendReq];
//    }else{
//        [self showPopupView:@"官人~\n请安端



微信朋友圈


//    if ([WXApi isWXAppInstalled] == 1) {
//        SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
//        sendReq.bText = NO;
//        sendReq.scene = 1;
//        WXMediaMessage *urlMessage = [WXMediaMessage message];
//        if (self.shareStr != nil) {
//            urlMessage.title = [NSString stringWithFormat:@"%@ %@",self.shareTitle ,self.shareStr];
//        }else {
//            urlMessage.title = @"天下";//标题
//        }
////            urlMessage.description = @"副标题";
//        
//        //    if (self.shareImage != nil) {
//        //        UIImageView *shareImageView = [[UIImageView alloc] init];
//        //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//        //            [shareImageView hr_setImageWithObjectKey:self.shareImage placeholderImage:nil options:(HRImageContentTypeWEBP) completed:^(UIImage *image, NSError *error) {
//        //                shareImageView.image = image;
//        //
//        //            }];
//        //        });
//        //        UIImage *image = shareImageView.image;
//        //        NSData *photo = UIImageJPEGRepresentation(image, 0.4);
//        //        [urlMessage setThumbImage:[UIImage imageWithData:photo]];
//        //    }else {
//        UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithContentsOfURL:[self shareImageUrl] encoding:(NSUTF8StringEncoding) error:nil]];
//        [urlMessage setThumbImage:image];
//        //    }
//        
//        WXWebpageObject *webObj = [WXWebpageObject object];
//    
//        webObj.webpageUrl = [self shareUrl];
//      
//        
//        urlMessage.mediaObject = webObj;
//        sendReq.message = urlMessage;
//        
//        [WXApi sendReq:sendReq];
//    }else{
//        [self showPopupView:@"官人~\n请安装微信客户端




QQ空间

//    if ([TencentApiInterface isTencentAppInstall:(kIphoneQQ)]) {
//
//        QQApiNewsObject *newsObj;
//        newsObj  = [QQApiNewsObject objectWithURL:[NSURL URLWithString:[self shareUrl]]
//                                                title:[self shareTitleString]
//                                          description:[self descriptionString]
//                                  previewImageURL:[NSURL URLWithString:[self shareImageUrl]]];
//     
//      
//        uint64_t cflag = 1;
//        [newsObj setCflag:cflag];
//        SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
//        //分享到QZone
//        [QQApiInterface SendReqToQZone:req];
//    }else{
//        [self showPopupView:@"官人~\n请安装QQ客户端"];
//    }

你可能感兴趣的:(iOS新浪微博 微信好友、微信朋友圈、QQ自身sdk分享方法)