微博分享-姬云鹏
Posted tarena_3G
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微博分享-姬云鹏相关的知识,希望对你有一定的参考价值。
一、先通过Xcode建立工程通过xib加载
xib:
视图控制器:
//
// RootViewController.h
// 微博平台分享内容
//
// Created by pengxun523 on 14-4-18.
// Copyright (c) 2014年 pengxun523. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RootViewController :UIViewController
@property (weak, nonatomic) IBOutletUITextView *postText;
@property (weak, nonatomic) IBOutletUITextField *postUrl;
@property (weak, nonatomic) IBOutletUITextField *postImage;
- (IBAction)WeiboBtn:(UIButton *)sender;
@property (weak, nonatomic) IBOutletUILabel *resultLabel;
@end
//
// RootViewController.m
// 微博平台分享内容
//
// Created by pengxun523 on 14-4-18.
// Copyright (c) 2014年 pengxun523. All rights reserved.
//
#import "RootViewController.h"
#import <Social/Social.h>
@interface RootViewController ()
@end
@implementation RootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
self = [superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];
if (self)
// Custom initialization
return self;
- (void)viewDidLoad
[superviewDidLoad];
_resultLabel.textColor = [UIColorredColor];
_postUrl.text =@"http://www.baidu.com";
_postImage.text =@"meimei.png";
// Do any additional setup after loading the view.
- (void)didReceiveMemoryWarning
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
//发送微博
- (IBAction)WeiboBtn:(UIButton *)sender
// NSString *str = @"http://www.baidu.com";
//判断服务器是否可以访问新浪微博
if([SLComposeViewControllerisAvailableForServiceType:SLServiceTypeSinaWeibo])
/*
此处可以选择 很多种包括facebook Twitter 但选择发送到facebook或者Twitter 都要先通过VPN翻墙
具体怎么做 请看这里 http://www.myvpnonly.com/misc/iphone
SOCIAL_EXTERN NSString *const SLServiceTypeTwitter NS_AVAILABLE(10_8, 6_0);
SOCIAL_EXTERN NSString *const SLServiceTypeFacebook NS_AVAILABLE(10_8, 6_0);
SOCIAL_EXTERN NSString *const SLServiceTypeSinaWeibo NS_AVAILABLE(10_8, 6_0);
SOCIAL_EXTERN NSString *const SLServiceTypeTencentWeibo NS_AVAILABLE(10_9, 7_0);
SOCIAL_EXTERN NSString *const SLServiceTypeLinkedIn NS_AVAILABLE(10_9, NA);
*/
NSLog(@"可以!!");
//使用SLServiceTypeSinaWeibo创建一个新浪微博view controller
SLComposeViewController *socialVC = [SLComposeViewControllercomposeViewControllerForServiceType:SLServiceTypeSinaWeibo];
//写一个block用于completionHandler初始化
//typedef void (^SLComposeViewControllerCompletionHandler)(SLComposeViewControllerResult result); 定义一个范围值为void 参数为SLComposeViewControllerResult的block 句柄保存发送完的信息
SLComposeViewControllerCompletionHandler myblock = ^(SLComposeViewControllerResult result)
if(result ==SLComposeViewControllerResultCancelled)
//是取消
_resultLabel.text =@"分享取消";
elseif(result ==SLComposeViewControllerResultDone)
_resultLabel.text =@"分享成功";
else
_resultLabel.text =@"分享失败";
;
//@property (nonatomic, copy) SLComposeViewControllerCompletionHandler completionHandler;
socialVC.completionHandler = myblock ;//初始化completionHandler为myblock
UIImage *image = [UIImageimageNamed:_postImage.text];
// UIImage *image = [UIImage imageWithContentsOfFile:_postImage.text];
NSURL *url = [NSURLURLWithString:_postUrl.text];
[socialVCsetInitialText:_postText.text];
[socialVCaddImage:image];
[socialVCaddURL:url];
[selfpresentViewController:socialVCanimated:YEScompletion:nil];
@end
真机测试!!运行结果:
以上是关于微博分享-姬云鹏的主要内容,如果未能解决你的问题,请参考以下文章