我为我的项目添加了一个测试目标,现在我想分离不会在应用程序目标上执行的代码部分。假设应用程序被调用TestMyApp
,我希望它是这样的:
-(void)addDevice:(Account*)account{
NSURL *url = [NSURL URLWithString:K_THINKERBELL_SERVER_URL];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
SBJsonWriter *jsonWriter = [[SBJsonWriter alloc] init];
NSDictionary *params = @{@"device_id":account.deviceID,
@"token":account.deviceToken ? account.deviceToken : @"fuygciureygfiyuergfyurgfuyergfuyerguy",
@"type":account.deviceName,
@"os_type":@"ios",
@"os_version":account.os,
@"accounts":_accounts};
NSString *js = [jsonWriter stringWithObject:params];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"PUT" path:@"/device" parameters:nil];
NSData *requestData = [NSData dataWithBytes:[js UTF8String] length:[js length]];
[request setHTTPBody:requestData];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
AFHTTPRequestOperation *operation = [httpClient HTTPRequestOperationWithRequest:request
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError *error = nil;
NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:&error];
if (error) {
NSLog(@"%@",JSON);
}
NSLog(@"%@",JSON);
if ([[JSON objectForKey:@"status"]isEqualToString:@"success"]) {
***#ifdef TestMyApp
some code here***
[self.testDelegate addDeviceJson:JSON type:@"addDevice"];
[self deviceAdded:[JSON objectForKey:@"uid"]];
[self.accountsDelegate deviceDidAdded];
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error){
}];
[httpClient enqueueHTTPRequestOperation:operation];
}