目录
Config.h
#define BASE_URL @"http://api.netkiller.cn:8080" #define CLIENTID @"api" #define SECRET @"secret" #define OAUTH_TOKEN @"/oauth/token" #define OAUTH_USERNAME @"blockchain" #define OAUTH_PASSWORD @"123456"
AppDelegate.m
#import "AppDelegate.h"
#import "YTKNetworkConfig.h"
#import "AFOAuth2Manager.h"
#import <AFNetworking.h>
#import "Config.h"
@interface AppDelegate ()
@property (nonatomic, strong) AFOAuthCredential *credential;
@property (nonatomic, strong) AFOAuth2Manager *OAuth2Manager;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//授权
NSURL *url = [NSURL URLWithString:BASE_URL];
AFOAuth2Manager *OAuth2Manager = [[AFOAuth2Manager alloc]initWithBaseURL:url clientID:CLIENTID secret:SECRET];
self.OAuth2Manager = OAuth2Manager;
[OAuth2Manager authenticateUsingOAuthWithURLString:OAUTH_TOKEN
username:OAUTH_USERNAME
password:OAUTH_PASSWORD
scope:@""
success:^(AFOAuthCredential *credential) {
// NSLog(@"********请求OauthToek成功***********");
self.credential = credential;
// [self testPost];
// [self testGet];
// [self uploadImage];
[self testJson];
}
failure:^(NSError *error) {
// NSLog(@"********请求OauthToekn失败begin***********\r\n%@\r\n*********请求OauthToekn失败end************",error);
}];
// Override point for customization after application launch.
return YES;
}
@end