Created
          November 26, 2013 23:22 
        
      - 
      
- 
        Save pierreant-p/7668098 to your computer and use it in GitHub Desktop. 
    Upload to Sketchfab with Cocoa
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // | |
| // AppDelegate.m | |
| // Upload to Sketchfab sample code | |
| // | |
| // Created by Pierre-Antoine Passet on 11/26/13. | |
| // Copyright (c) 2013 Sketchfab. All rights reserved. | |
| // | |
| #import "AppDelegate.h" | |
| #import "AFHTTPRequestOperation.h" | |
| #import "AFHTTPRequestOperationManager.h" | |
| @implementation AppDelegate | |
| - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
| { | |
| self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
| self.window.backgroundColor = [UIColor whiteColor]; | |
| [self.window makeKeyAndVisible]; | |
| [self postModelToSketchfab]; | |
| return YES; | |
| } | |
| - (void)postModelToSketchfab | |
| { | |
| NSString *token = @"XXXXXX"; | |
| NSString *filePath = [[NSBundle mainBundle] pathForResource:@"airboat" ofType:@"obj"]; | |
| NSURL *fileUrlPath = [NSURL fileURLWithPath:filePath]; | |
| NSDictionary *data = @{ | |
| @"title": @"Test model from Cocoa", | |
| @"description": @"My great description", | |
| @"filenameModel": @"airboat.obj", | |
| @"tags": @"cocao uploader snippet", | |
| @"token": token, | |
| @"private": @YES, | |
| @"password": @"" | |
| }; | |
| AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; | |
| [manager POST:@"https://api.sketchfab.com/v1/models" | |
| parameters:data constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { | |
| [formData appendPartWithFileURL:fileUrlPath | |
| name:@"fileModel" | |
| error:nil]; | |
| } success:^(AFHTTPRequestOperation *operation, id responseObject) { | |
| NSLog(@"Success: %@", responseObject); | |
| } failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
| NSLog(@"Error: %@", error); | |
| }];} | |
| @end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment