/WeiboSDKDemo/WeiboSDKDemo/AppDelegate.m

https://gitlab.com/Mr.Tomato/weibo_ios_sdk_sso-oauth · Objective C · 121 lines · 85 code · 21 blank · 15 comment · 4 complexity · cddc3b9112bc793b76ab3b3ae3992690 MD5 · raw file

  1. //
  2. // AppDelegate.m
  3. // WeiboSDKDemo
  4. //
  5. // Created by Wade Cheng on 3/29/13.
  6. // Copyright (c) 2013 SINA iOS Team. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "SendMessageToWeiboViewController.h"
  10. #import "ProvideMessageForWeiboViewController.h"
  11. @interface WBBaseRequest ()
  12. - (void)debugPrint;
  13. @end
  14. @interface WBBaseResponse ()
  15. - (void)debugPrint;
  16. @end
  17. @implementation AppDelegate
  18. @synthesize wbtoken;
  19. - (void)dealloc
  20. {
  21. [_window release];
  22. [_viewController release];
  23. [super dealloc];
  24. }
  25. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  26. {
  27. [WeiboSDK enableDebugMode:YES];
  28. [WeiboSDK registerApp:kAppKey];
  29. self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
  30. // Override point for customization after application launch.
  31. self.viewController = [[[SendMessageToWeiboViewController alloc] initWithNibName:nil bundle:nil] autorelease];
  32. self.window.rootViewController = self.viewController;
  33. [self.window makeKeyAndVisible];
  34. return YES;
  35. }
  36. - (void)applicationWillResignActive:(UIApplication *)application
  37. {
  38. // 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.
  39. // 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.
  40. }
  41. - (void)applicationDidEnterBackground:(UIApplication *)application
  42. {
  43. // 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.
  44. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  45. }
  46. - (void)applicationWillEnterForeground:(UIApplication *)application
  47. {
  48. // 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.
  49. }
  50. - (void)applicationDidBecomeActive:(UIApplication *)application
  51. {
  52. // 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.
  53. }
  54. - (void)applicationWillTerminate:(UIApplication *)application
  55. {
  56. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  57. }
  58. - (void)didReceiveWeiboRequest:(WBBaseRequest *)request
  59. {
  60. if ([request isKindOfClass:WBProvideMessageForWeiboRequest.class])
  61. {
  62. ProvideMessageForWeiboViewController *controller = [[[ProvideMessageForWeiboViewController alloc] init] autorelease];
  63. [self.viewController presentModalViewController:controller animated:YES];
  64. }
  65. }
  66. - (void)didReceiveWeiboResponse:(WBBaseResponse *)response
  67. {
  68. if ([response isKindOfClass:WBSendMessageToWeiboResponse.class])
  69. {
  70. NSString *title = @"发送结果";
  71. NSString *message = [NSString stringWithFormat:@"响应状态: %d\n响应UserInfo数据: %@\n原请求UserInfo数据: %@",
  72. response.statusCode, response.userInfo, response.requestUserInfo];
  73. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
  74. message:message
  75. delegate:nil
  76. cancelButtonTitle:@"确定"
  77. otherButtonTitles:nil];
  78. [alert show];
  79. [alert release];
  80. }
  81. else if ([response isKindOfClass:WBAuthorizeResponse.class])
  82. {
  83. NSString *title = @"认证结果";
  84. NSString *message = [NSString stringWithFormat:@"响应状态: %d\nresponse.userId: %@\nresponse.accessToken: %@\n响应UserInfo数据: %@\n原请求UserInfo数据: %@",
  85. response.statusCode, [(WBAuthorizeResponse *)response userID], [(WBAuthorizeResponse *)response accessToken], response.userInfo, response.requestUserInfo];
  86. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
  87. message:message
  88. delegate:nil
  89. cancelButtonTitle:@"确定"
  90. otherButtonTitles:nil];
  91. self.wbtoken = [(WBAuthorizeResponse *)response accessToken];
  92. [alert show];
  93. [alert release];
  94. }
  95. }
  96. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
  97. {
  98. return [WeiboSDK handleOpenURL:url delegate:self];
  99. }
  100. @end