/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
- //
- // AppDelegate.m
- // WeiboSDKDemo
- //
- // Created by Wade Cheng on 3/29/13.
- // Copyright (c) 2013 SINA iOS Team. All rights reserved.
- //
- #import "AppDelegate.h"
- #import "SendMessageToWeiboViewController.h"
- #import "ProvideMessageForWeiboViewController.h"
- @interface WBBaseRequest ()
- - (void)debugPrint;
- @end
- @interface WBBaseResponse ()
- - (void)debugPrint;
- @end
- @implementation AppDelegate
- @synthesize wbtoken;
- - (void)dealloc
- {
- [_window release];
- [_viewController release];
- [super dealloc];
- }
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- [WeiboSDK enableDebugMode:YES];
- [WeiboSDK registerApp:kAppKey];
-
-
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
- // Override point for customization after application launch.
- self.viewController = [[[SendMessageToWeiboViewController alloc] initWithNibName:nil bundle:nil] autorelease];
- self.window.rootViewController = self.viewController;
- [self.window makeKeyAndVisible];
- return YES;
- }
- - (void)applicationWillResignActive:(UIApplication *)application
- {
- // 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.
- // 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.
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application
- {
- // 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.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application
- {
- // 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.
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application
- {
- // 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.
- }
- - (void)applicationWillTerminate:(UIApplication *)application
- {
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
- }
- - (void)didReceiveWeiboRequest:(WBBaseRequest *)request
- {
- if ([request isKindOfClass:WBProvideMessageForWeiboRequest.class])
- {
- ProvideMessageForWeiboViewController *controller = [[[ProvideMessageForWeiboViewController alloc] init] autorelease];
- [self.viewController presentModalViewController:controller animated:YES];
- }
- }
- - (void)didReceiveWeiboResponse:(WBBaseResponse *)response
- {
- if ([response isKindOfClass:WBSendMessageToWeiboResponse.class])
- {
- NSString *title = @"发送结果";
- NSString *message = [NSString stringWithFormat:@"响应状态: %d\n响应UserInfo数据: %@\n原请求UserInfo数据: %@",
- response.statusCode, response.userInfo, response.requestUserInfo];
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
- message:message
- delegate:nil
- cancelButtonTitle:@"确定"
- otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
- else if ([response isKindOfClass:WBAuthorizeResponse.class])
- {
- NSString *title = @"认证结果";
- NSString *message = [NSString stringWithFormat:@"响应状态: %d\nresponse.userId: %@\nresponse.accessToken: %@\n响应UserInfo数据: %@\n原请求UserInfo数据: %@",
- response.statusCode, [(WBAuthorizeResponse *)response userID], [(WBAuthorizeResponse *)response accessToken], response.userInfo, response.requestUserInfo];
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
- message:message
- delegate:nil
- cancelButtonTitle:@"确定"
- otherButtonTitles:nil];
- self.wbtoken = [(WBAuthorizeResponse *)response accessToken];
-
- [alert show];
- [alert release];
- }
- }
- - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
- {
- return [WeiboSDK handleOpenURL:url delegate:self];
- }
- @end