Implementing an iOS OOEmbedTokenGenerator

To use the Ooyala Player Token for user authorization your iOS app must implement OOEmbedTokenGenerator.

Click here to view the example used in this tutorial, and use the following steps to implement the OOEmbedTokenGenerator in your project.

  1. on the project ViewController.h file and add the following import statement:
    #import "OOEmbedTokenGenerator.h" 
  2. Implement OOEmbedTokenGenerator in the UIViewController. The syntax is shown in the following example:
    @interface ViewController : UIViewController <OOEmbedTokenGenerator>  
  3. Open the project ViewController.m file and create or edit the ooyalaPlayerViewController to call the method overload that takes embedTokenGenerator. The syntax is shown in the following example:
    / Create the Ooyala ViewController, with self as the embed token generator
    OOOoyalaPlayer *player = [
       [OOOoyalaPlayer alloc] initWithPcode:self.pcode
       domain:[[OOPlayerDomain alloc]initWithString:self.playerDomain]
    self.ooyalaPlayerViewController = [[OOOoyalaPlayerViewController alloc] initWithPlayer:player];
  4. A server-side generated token can only be created by the customer so content is authorized for playback on authorized sites. The client receives it and submits it to embedTokenGenerator(). These tokens should not be created on the client. The API secret should only be on the server and should not be publicly visible. This example is only useful for debugging but should not be used in production. Implement tokenForEmbedCodes in the ViewController.m file. The syntax is shown in the following example:
      * Get the Ooyala Player Token to play the embed code.
      * This should contact your servers to generate the OPT server-side.
      * For debugging, you can use Ooyala's EmbeddedSecureURLGenerator to create local embed tokens
    - (void)tokenForEmbedCodes:(NSArray *)embedCodes callback:(OOEmbedTokenCallback)callback {
       NSMutableDictionary* params = [NSMutableDictionary dictionary];
       params[@"account_id"] = self.accountId;
       NSString* uri = [NSString stringWithFormat:@"/sas/embed_token/%@/%@", self.pcode, [embedCodes componentsJoinedByString:@","]];
       OOEmbeddedSecureURLGenerator* urlGen = [[OOEmbeddedSecureURLGenerator alloc] initWithAPIKey:self.apiKey secret:self.secret];
       NSURL* embedTokenUrl = [urlGen secureURL:self.authorizeHost uri:uri params:params];
      callback([embedTokenUrl absoluteString]);

The iOS Mobile SDK Sample Apps folder includes a complete working sample app with OOEmbedTokenGenerator implemented. From the SDK archive, navigate to:


해당 내용이 도움 되었습니까?