本身做的To Do List 小软件

(5)登录、登出、获取授权信息、关注制定微博

 安卓版
源程序

图片 1

2017-12-17修改  双击新增 里 显示的 剪贴板里之情节

图片 2

图片 3

(6)测试DEMO截图:

我做的To Do List 小软件

图片 4

2017-09-25增  网址的 打开超链接功能

 

tulater-to-do-list

 

图片 5

(2)根据实际情况,引入相关的库,参考官文档。

 

老二种植授权法要在plist中配置Scheme。SSO默认是开拓的免欲安排。在AppDelegate中实现回调。

  1. //  
  2. //  LoginViewController.m  
  3. //  ShareSDKTest  
  4. //  
  5. //  Created by wangdalei on 14-6-23.  
  6. //  Copyright (c) 2014年 王大雷. All rights reserved.  
  7. //  
  8.   
  9. #import “LoginViewController.h”  
  10. #import <ShareSDK/ShareSDK.h>  
  11.   
  12. @interface LoginViewController ()  
  13.   
  14. -(IBAction)loginWithSina:(id)sender;  
  15.   
  16. -(IBAction)loginWithQQ:(id)sender;  
  17.   
  18. -(IBAction)loginoutWithSina:(id)sender;  
  19.   
  20. -(IBAction)loginoutWithQQ:(id)sender;  
  21.   
  22. -(IBAction)guanzhuUs:(id)sender;  
  23.   
  24. -(void)reloadStateWithType:(ShareType)type;  
  25.   
  26. @end  
  27.   
  28. @implementation LoginViewController  
  29.   
  30. – (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {  
  31.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
  32.     if (self) {  
  33.     }  
  34.     return self;  
  35. }  
  36.   
  37. – (void)viewDidLoad {  
  38.     [super viewDidLoad];  
  39. }  
  40.   
  41. – (void)didReceiveMemoryWarning {  
  42.     [super didReceiveMemoryWarning];  
  43. }  
  44.   
  45. – (IBAction)loginWithSina:(id)sender {  
  46.     [ShareSDK getUserInfoWithType:ShareTypeSinaWeibo authOptions:nil result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {  
  47.         NSLog(@”%d”,result);  
  48.         if (result) {  
  49.             //成功登录后,判断该用户之ID是否在大团结的数据库被。  
  50.             //如果有一直登录,没有就用该用户的ID和有关材料在数据库中创造新用户。  
  51.             [self reloadStateWithType:ShareTypeSinaWeibo];  
  52.         }  
  53.     }];  
  54. }  
  55.   
  56.   
  57. -(IBAction)loginWithQQ:(id)sender{  
  58.     [ShareSDK getUserInfoWithType:ShareTypeQQSpace authOptions:nil result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {  
  59.         NSLog(@”%d”,result);  
  60.         if (result) {  
  61.             //成功登录后,判断该用户的ID是否在团结之数据库中。  
  62.             //如果有一直登录,没有就拿欠用户之ID和相关材料在数据库被开创新用户。  
  63.             [self reloadStateWithType:ShareTypeQQSpace];  
  64.         }  
  65.     }];  
  66. }  
  67.   
  68. -(IBAction)loginoutWithSina:(id)sender{  
  69.     [ShareSDK cancelAuthWithType:ShareTypeSinaWeibo];  
  70.     [self reloadStateWithType:ShareTypeSinaWeibo];  
  71. }  
  72.   
  73. -(IBAction)loginoutWithQQ:(id)sender{  
  74.     [ShareSDK cancelAuthWithType:ShareTypeQQSpace];  
  75.     [self reloadStateWithType:ShareTypeQQSpace];  
  76. }  
  77.   
  78. -(void)reloadStateWithType:(ShareType)type{  
  79.     //现实授权信息,包括授权ID、授权有效期等。  
  80.     //此处可以于用户进入以的时刻一直调用,如授权信息不呢空且不超时可帮用户自动实现登录。  
  81.     id<ISSPlatformCredential> credential = [ShareSDK getCredentialWithType:type];  
  82.     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@”TEXT_TIPS”, @”提示”)  
  83.                                                         message:[NSString stringWithFormat:  
  84.                                                                  @”uid = %@\ntoken = %@\nsecret = %@\n expired = %@\nextInfo = %@”,  
  85.                                                                  [credential uid],  
  86.                                                                  [credential token],  
  87.                                                                  [credential secret],  
  88.                                                                  [credential expired],  
  89.                                                                  [credential extInfo]]  
  90.                                                        delegate:nil  
  91.                                               cancelButtonTitle:NSLocalizedString(@”TEXT_KNOW”, @”知道了”)  
  92.                                               otherButtonTitles:nil];  
  93.     [alertView show];  
  94. }  
  95.   
  96. //关注用户  
  97. -(IBAction)guanzhuUs:(id)sender{  
  98.     [ShareSDK followUserWithType:ShareTypeSinaWeibo         //平台类型  
  99.                            field:@”ShareSDK”                //关注用户的名或者ID  
  100.                        fieldType:SSUserFieldTypeName        //字段类型,用于指定第二只参数是名或者ID  
  101.                      authOptions:nil                        //授权选项  
  102.                     viewDelegate:nil                        //授权视图委托  
  103.                           result:^(SSResponseState state, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {  
  104.                               if (state == SSResponseStateSuccess) {  
  105.                                   NSLog(@”关注成功”);  
  106.                               } else if (state == SSResponseStateFail) {  
  107.                                   NSLog(@”%@”, [NSString stringWithFormat:@”关注失败:%@”, error.errorDescription]);  
  108.                               }  
  109.                           }];  
  110. }  
  111.   
  112.   
  113. @end  

图片 6

  1. -(IBAction)share:(id)sender{  
  2.     NSString *imagePath = [[NSBundle mainBundle] pathForResource:@”card”  ofType:@”png”];  
  3.     //构造分享内容  
  4.     id<ISSContent> publishContent = [ShareSDK content:@”分享内容测试”  
  5.                                        defaultContent:@”默认分享内容测试,没内容时展示”  
  6.                                                 image:[ShareSDK imageWithPath:imagePath]  
  7.                                                 title:@”pmmq”  
  8.                                                   url:@”http://www.sharesdk.cn”  
  9.                                           description:@”这是一样修测试信息”  
  10.                                             mediaType:SSPublishContentMediaTypeNews];  
  11.     [ShareSDK showShareActionSheet:nil  
  12.                          shareList:nil  
  13.                            content:publishContent  
  14.                      statusBarTips:YES  
  15.                        authOptions:nil  
  16.                       shareOptions: nil  
  17.                             result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {  
  18.                                 if (state == SSResponseStateSuccess)  
  19.                                 {  
  20.                                     NSLog(@”分享成功”);  
  21.                                 }  
  22.                                 else if (state == SSResponseStateFail)  
  23.                                 {  
  24.                                     NSLog(@”分享失败”);  
  25.                                 }  
  26.                             }];  
  27. }  

(5)你恐怕会见相有的用到得第三方登录的,一种是弹出webView加载的新浪微博要qq的网页授权,还有同种植是超越反至地头的已经设置之新浪微博以或qq应用进行授权。第二种植授权法比SSO授权,体验会比较好有,因为未需用户输入新浪微博还是QQ的用户称及密码。

(1)官方下载ShareSDK iOS 2.8.8,地址:http://sharesdk.cn/

 

 

 

(3)在路的AppDelegate中一般景象下出三单操作,第一凡是登记ShareSDK,第二凡注册各个平台的账号,第三是关于微信等使之回调处理。

  1. //  
  2. //  AppDelegate.m  
  3. //  ShareSDKTest  
  4. //  
  5. //  Created by wangdalei on 14-6-23.  
  6. //  Copyright (c) 2014年 王大雷. All rights reserved.  
  7. //  
  8.   
  9. #import “AppDelegate.h”  
  10. #import “RootViewController.h”  
  11. #import <ShareSDK/ShareSDK.h>  
  12. #import “WeiboApi.h”  
  13. #import <TencentOpenAPI/QQApiInterface.h>  
  14. #import <TencentOpenAPI/TencentOAuth.h>  
  15. #import “WXApi.h”  
  16. #import <TencentOpenAPI/QQApiInterface.h>  
  17. #import <TencentOpenAPI/TencentOAuth.h>  
  18.   
  19. @implementation AppDelegate  
  20. @synthesize rootVC;  
  21.   
  22. – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
  23.     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  24.     if (self.rootVC==nil) {  
  25.         self.rootVC = [[RootViewController alloc]initWithNibName:@”RootViewController” bundle:nil];  
  26.     }  
  27.     UINavigationController *rootNav = [[UINavigationController alloc]initWithRootViewController:self.rootVC];  
  28.     self.window.rootViewController = rootNav;  
  29.     self.window.backgroundColor = [UIColor whiteColor];  
  30.     [self.window makeKeyAndVisible];  
  31.       
  32.       
  33.     <span style=”color:#ff0000;”>[ShareSDK registerApp:@”1a2e7ab5fb6c”];</span>  
  34.       
  35.    <span style=”color:#3366ff;”> //添加新浪微博应用 注册网址 http://open.weibo.com  wdl@pmmq.com 此处需要替换成自己行使之  
  36.     [ShareSDK connectSinaWeiboWithAppKey:@”3201194191″  
  37.                                appSecret:@”0334252914651e8f76bad63337b3b78f”  
  38.                              redirectUri:@”http://appgo.cn"\];  
  39.       
  40.     //添加腾讯微博使用 注册网址 http://dev.t.qq.com wdl@pmmq.com 此处需要替换成自己以的  
  41.     [ShareSDK connectTencentWeiboWithAppKey:@”801307650″  
  42.                                   appSecret:@”ae36f4ee3946e1cbb98d6965b0b2ff5c”  
  43.                                 redirectUri:@”http://www.sharesdk.cn”  
  44.                                    wbApiCls:[WeiboApi class]];  
  45.       
  46.     //添加QQ空间利用 注册网址  http://connect.qq.com/intro/login/ wdl@pmmq.com 此处需要替换成自己行使之  
  47.     [ShareSDK connectQZoneWithAppKey:@”100371282″  
  48.                            appSecret:@”aed9b0303e3ed1e27bae87c33761161d”  
  49.                    qqApiInterfaceCls:[QQApiInterface class]  
  50.                      tencentOAuthCls:[TencentOAuth class]];  
  51.       
  52.     //此参数为申请之微信AppID wdl@pmmq.com 此处需要替换成自己以的  
  53.     [ShareSDK connectWeChatWithAppId:@”wx4868b35061f87885″ wechatCls:[WXApi class]];  
  54.       
  55.     //添加QQ应用 该参数填入申请的QQ AppId wdl@pmmq.com 此处需要替换成自己运的  
  56.     [ShareSDK connectQQWithQZoneAppKey:@”100371282″  
  57.                      qqApiInterfaceCls:[QQApiInterface class]  
  58.                        tencentOAuthCls:[TencentOAuth class]];</span>  
  59.       
  60.     return YES;  
  61. }  
  62.   
  63.   
  64. – (void)applicationWillResignActive:(UIApplication *)application {  
  65.     // 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.  
  66.     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.  
  67. }  
  68.   
  69. – (void)applicationDidEnterBackground:(UIApplication *)application {  
  70.     // 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.   
  71.     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.  
  72. }  
  73.   
  74. – (void)applicationWillEnterForeground:(UIApplication *)application {  
  75.     // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.  
  76. }  
  77.   
  78. – (void)applicationDidBecomeActive:(UIApplication *)application {  
  79.     // 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.  
  80. }  
  81.   
  82. – (void)applicationWillTerminate:(UIApplication *)application {  
  83.     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.  
  84. }  
  85.   
  86.   
  87. <span style=”color:#ff6600;”>#pragma mark – WX回调  
  88.   
  89. – (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {  
  90.     return [ShareSDK handleOpenURL:url wxDelegate:self];  
  91. }  
  92.   
  93. – (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {  
  94.     return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];  
  95. }  
  96.   
  97. #pragma mark – WXApiDelegate  
  98.   
  99. /*! @brief 收到一个源于微信的恳求,第三着应用程序处理了晚调用sendResp向微信发送结果 
  100.  * 
  101.  * 收到一个来源微信的要,异步处理就后须调用sendResp发送处理结果给微信。 
  102.  * 可能接受的乞求有GetMessageFromWXReq、ShowMessageFromWXReq等。 
  103.  * @param req 具体求内容,是机关释放的 
  104.  */  
  105. -(void) onReq:(BaseReq*)req{  
  106.       
  107. }  
  108.   
  109. /*! @brief 发送一个sendReq后,收到微信的对答 
  110.  * 
  111.  * 收到一个来源微信的处理结果。调用一差sendReq后会见吸收onResp。 
  112.  * 可能收取的处理结果有SendMessageToWXResp、SendAuthResp等。 
  113.  * @param resp具体的回内容,是机关释放的 
  114.  */  
  115. -(void) onResp:(BaseResp*)resp{  
  116.       
  117. }  
  118. </span>  
  119. @end  

 

(4)信息分享。