Using the update iOS SDK

Archived from the Transloadit support forum. Originally posted on December 9, 2014; details may be outdated, see our docs for current behavior. Original thread

Hi Transload-it support,

We’ve changed from the original iOS Transload-it SDK to the latest SDK (to support Apple’s 64-bit app requirement).
Most of the Transload-it calls ported across easily, with a 1:1 match of old to new API’s as follows:

OLD SDK:

    TransloaditRequest* transload = [[TransloaditRequest alloc] initWithCredentials: [Configuration sharedConfiguration].transloaditKey secret: [Configuration sharedConfiguration].transloaditSecret];
    [transload setTemplateId: [Configuration sharedConfiguration].videoTemplateId];
    [transload addRawFile: _exportedVideoPath withFileName: @"video.mp4" addContentType: @"video/mp4"];
    [transload setNumberOfTimesToRetryOnTimeout: 5];
    
    NSDictionary* steps = @{
        @"export": @{
            @"bucket": [Configuration sharedConfiguration].awsBucket,
            @"path": [NSString stringWithFormat: @"uploads/story/%d/story_video_${assembly.id}_${previous_step.name}", _userId],
            },
        @"save": @{
            @"bucket": [Configuration sharedConfiguration].awsBucket,
            @"path": [NSString stringWithFormat: @"uploads/story/%d/story_video_${assembly.id}_original", _userId],
            }
    };
    [[transload params] setObject: steps forKey: @"steps"];
    [[transload params] setObject: [Configuration sharedConfiguration].videoNotificationUrl forKey: @"notify_url"];
    [transload setDelegate: self];
    [transload startAsynchronous];

NEW SDK:

    NSObject<ITransloadit>* transloadit = [[Transloadit alloc] init: [Configuration sharedConfiguration].transloaditKey];
    [transloadit useSignature: [Configuration sharedConfiguration].transloaditSecret];
       
    NSObject<IAssemblyBuilder>* assembly = [[AssemblyBuilder alloc] init];
      
    [assembly setTemplateID: [Configuration sharedConfiguration].videoTemplateId];
    NSError* error;
    [assembly addFileWithName: @"video.mp4" file: [NSData dataWithContentsOfURL: [NSURL URLWithString: _exportedVideoPath]] withError: error];
        
    NSObject<IStep>* exportStep = [[Step alloc] init];
    [exportStep setOptionKey: @"bucket" object: [Configuration sharedConfiguration].awsBucket];
    [exportStep setOptionKey: @"path" object: [NSString stringWithFormat: @"uploads/story/%d/story_video_${assembly.id}_${previous_step.name}", _userId]];
    [assembly addStepName: @"export" step: exportStep];
        
    NSObject<IStep>* saveStep  = [[Step alloc] init];
    [saveStep setOptionKey: @"bucket" object: [Configuration sharedConfiguration].awsBucket];
    [saveStep setOptionKey: @"path" object: [NSString stringWithFormat: @"uploads/story/%d/story_video_${assembly.id}_original", _userId]];
    [assembly addStepName: @"save" step: saveStep];
        
    [assembly setNotifyURL: [Configuration sharedConfiguration].videoNotificationUrl];
        
    TransloaditResponse* response = [transloadit invokeAssembly: assembly withError: error];

I have a few questions on different API functionality:

  1. The number of times to retry on timeout (setNumberOfTimesToRetryOnTimeout). Is there an new SDK equivalent?
  2. The old addRawFile:withFileName:addContentType: doesn’t quite match addFileWithName:file:withError.
    2a. Does the content type (video/mp4) of the old SDK not need to appear anywhere using the new SDK? 2b. Does the old SDK stream the file from disk whereas the new SDK needs to load into memory the audio clip to send? (Or did the old SDK also internally load the entire audio clip into memory?)
  3. and there is also a delay problem with the new SDK. After 10 seconds of attempting to send to Transload-it, the request time-outs with some ERROR:’s printed to the console, then it works after another 13 seconds.
    What do the ERROR:’s mean and how do we go about fixing this to make the new SDK work as well as the old SDK?
2014-12-09 18:01:53.887 MobileStorypark[19084:1283850] VoiceUploadJob.run:29 Sending voice to Transloadit

2014-12-09 18:02:03.890 MobileStorypark[19084:1283949] ERROR: DefaultHttpExecutor -- The request timed out.
2014-12-09 18:02:03.891 MobileStorypark[19084:1283949] ERROR: TransloaditRequest -- (null)
2014-12-09 18:02:03.891 MobileStorypark[19084:1283949] ERROR: Transloadit -- (null) -- Bored instance host is invalid using default path (null)

2014-12-09 18:02:16.841 MobileStorypark[19084:1283949] INFO: DefaultHttpExecutor -- {"ok":"ASSEMBLY_COMPLETED","message":"The assembly was successfully completed.","assembly_id":"REDACTED","parent_id":null,"account_id":"REDACTED","template_id":"REDACTED","instance":"sihaam.transloadit.com","assembly_url":"http://api2.sihaam.transloadit.com/assemblies/REDACTED","assembly_ssl_url":"https://sihaam.transloadit.com/assemblies/REDACTED","bytes_received":21275,"bytes_expected”: …

Thanks.

Any updates?

Hey Matt,

sorry for the long delay, this ticket slipped through the cracks. : /

Do you mind if we make it public so that our external iOS Dev Team can take a look at it?

Kind regards,
Tim

Co-Founder Transloadit
@tim_kos

Yes that’s fine Tim, looking forward to more information.

Hey Matt,

I have contacted them. I hope we’ll get a good answer here soon.

Kind regards,
Tim

Co-Founder Transloadit
@tim_kos

Hi,

For item 3, the first timeout is after asking the server for a cached worker to connect to, if available that returns immediately but we give it 10 seconds by default. If not available then we ask for a new one, and set a long timeout of 3 minutes.

You might be able to set defaultRequestTimeout to < 10 seconds if you want to gain time, but it might end up taking longer as a result depending on the server status and the network responsiveness.

Hope that helps!
Mike

Hey Matt,

did you see Mike’s reply? Did it help?

Kind regards,
Tim

Co-Founder Transloadit
@tim_kos

Hi Tim,

I talked to our contractor today about it - how often will the SDK get a cached worker compared to not (and timing out and logging the error)?

If it’s an edge case to hit that, then we’re not too worried, but if it always tries for 10 seconds before giving up we’d want to work around the delay.

Thanks,
Mathew Hartley

Hey Mathew,

in fact we changed our routing a few weeks ago to rely on AWS load balancers with latency based routing to the cloud that is closest to you. It will always pick the machine that has the lowest latency, i.e is the least busy one and the whole bored logic thing that the SDK is currently relying on will soon be a thing of the past, too.

So in other words, this should be a real edge case that you should not worry about.

Kind regards,
Tim

Co-Founder Transloadit
@tim_kos