Question

I was following a tutorial on basic database interaction with apps, and I ran in to a slight problem. It had me using an ASIHTTPRequest API which I read online was outdated, and even Xcode told me not to use it. So, I downloaded and installed AFNetworking. The only problem, being a noob following a tutorial, I have no Idea what to do now. I have all the Json, MBProgressHUD, and AFNetworking files in my project, but I can't change the code from the tutorial in to AFNetworking friendly code. Could someone please help me out?

Here is the code from the tutorial:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    NSLog(@"Want to redeem: %@", textField.text);

    // Get device unique ID
    UIDevice *device = [UIDevice currentDevice];
    NSString *uniqueIdentifier = [device uniqueIdentifier];

    // Start request
    NSString *code = textField.text;
    NSURL *url = [NSURL URLWithString:@"http://www.wildfables.com/promos/"];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setPostValue:@"1" forKey:@"rw_app_id"];
    [request setPostValue:code forKey:@"code"];
    [request setPostValue:uniqueIdentifier forKey:@"device_id"];
    [request setDelegate:self];
    [request startAsynchronous];

    // Hide keyword
    [textField resignFirstResponder];

    // Clear text field
    textView.text = @"";

    return TRUE;
}
Was it helpful?

Solution

You can POST using AFNetworking like so:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"foo": @"bar"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

I would also suggest using SVProgressHUD here as it is easier to implement.

And, using apps using UDIDs will not be accepted by the app store anymore. Source

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top