Objective-C SDK¶
The Objective-C SDK is available on GitHub. This SDK allows you to integrate Dailymotion in you iOS or Mac OS X applications.
Call Methods¶
The Objective-C SDK implements the Dailymotion Graph API using the Advanced API protocol. For a list of all available methods, see API Reference. To call a method using the Objective-C SDK, use the request:delegate: method as follow:
dailymotion = [[Dailymotion alloc] init];
[dailymotion request:@"/videos"
withArguments:[NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObjects:@"id", @"title"], @"fields", nil]
delegate:self];
To get the result, you have to implement the dailymotion:didReturnResult:userInfo: delegate method as follow:
- (void)dailymotion:(Dailymotion *)dailymotion didReturnResult:(NSDictionary *)result userInfo:(NSDictionary *)userInfo
{
NSArray *videos = [result objectForKey:@"list"];
}
If an error occurs, the dailymotion:didReturnError:userInfo: delegate method is called.
- (void)dailymotion:(Dailymotion *)dailymotion didReturnError:(NSError *)error userInfo:(NSDictionary *)userInfo;
{
[[[[UIAlertView alloc] initWithTitle:@"Error"
message:[error.localizedDescription]
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil] autorelease] show];
}
Authenticate¶
The Objective-C SDK implements three granting methods of OAuth 2.0: token, password and client_credentials.
Token Grant Type¶
This grant type is the one you should use in most cases. With this grant type, an UIWebView under iOS or a WebView on Mac OS X is opened with an authorization request page presented to the end-user.
Here is a usage example:
dailymotion = [[Dailymotion alloc] init];
[dailymotion setGrantType:DailymotionGrantTypeToken
withAPIKey:apiKey secret:apiSecret scope:@"read"];
[dailymotion request:uri withArguments:arguments delegate:self];
TODO: This grant type support is under construction
Password Grant Type¶
If the token grant type doesn’t suits your application workflow, you can request end-user credentials and use the password grant type to authenticate requests. Note that you MUST NOT store end-user credentials.
Here is a usage example:
dailymotion = [[Dailymotion alloc] init];
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:
kDMUsername, @"username", kDMPassword, @"password", nil];
[dailymotion setGrantType:DailymotionGrantTypePassword
withAPIKey:apiKey secret:apiSecret scope:@"read"
info:info];
[dailymotion request:uri withArguments:arguments delegate:self];
Client Credentials Grant Type¶
If you don’t need to access the Dailymotion API on behalf of a user because, for instance, you plan to only access public data, you can use the client credentials grant type. With this grant type, you will only have access to public data or private data of the user owning the API key.
Here is a usage example:
dailymotion = [[Dailymotion alloc] init];
[dailymotion setGrantType:DailymotionGrantTypeClientCredentials
withAPIKey:apiKey secret:apiSecret scope:@"read"];
[dailymotion request:uri withArguments:arguments delegate:self];
Upload File¶
Certain methods like POST /me/videos requires a URL to a file. To create those URLs, the uploadFile:delegate: method have to be used like this:
[dailymotion uploadFile:@"/path/to/file.mp4" delegate:self];
You have to implement the dailymotion:didUploadFileAtURL: delegate method to get the URL returned by the server. You can then use this URL as an argument to methods requiring such parameter. For instance to create a video:
- (void)dailymotion:(Dailymotion *)dailymotion didUploadFileAtURL:(NSString *)URL;
{
[dailymotion request:@"POST /me/videos"
withArguments:[NSDictionary dictionaryWithObject:URL forKey:@"url"]
delegate:self];
}
In case of error, the dailymotion:didReturnError:userInfo: will be called. To implement progress indicator, you can implement the dailymotion:didSendFileData:totalBytesWritten:totalBytesExpectedToWrite: delegate method.
Player¶
To display a Dailymotion video in an iOS application (Mac OS X support under construction), the Dailymotion SDK provides the DailymotionPlayerViewController class. To instanciate a player controller, use the player: method:
DailymotionPlayerViewController *playerController [dailymotion player:@"xl2k3"];
playerController.delegate = self;
You can then call method, access properties and change some of them to control the playback of the video. The player return events using the dailymotionPlayer:didReceiveEvent: delegate method:
- (void)dailymotionPlayer:(DailymotionPlayerViewController *)player didReceiveEvent:(NSString *)eventName
{
if ([eventName isEqualToString:@"timeupdate"])
{
progressBar.value = player.currentTime / player.duration;
}
}
DailymotionPlayerViewController Properties¶
| Name | Type | Description |
|---|---|---|
| autoplay | BOOL | A Boolean value that determines whether the media resource plays automatically when available (read-only). |
| currentTime | float | The current playback position in seconds. Change this value to seek in the video. |
| bufferedTime | float | The part of the media resource that have been downloaded in seconds (read-only). |
| duration | float | The length of the media resource in seconds (read-only). |
| seeking | BOOL | A Boolean value that indicates whether the element is seeking (read-only). |
| error | NSError* | The last error that occurend for this player (userInfo are code, title and message |
| ended | BOOL | A Boolean value that indicates whether the media played to the end (read-only). |
| muted | BOOL | A Boolean value that determines whether the audio content should be muted. |
| volume | float | The volume of the video between 0 and 1. |
| paused | BOOL | A Boolean value that indicates whether the media is paused (read-only). |
| fullscreen | BOOL | A Boolean value that indicates whether the video is displayed fullscreen. |
DailymotionPlayerViewController Methods¶
| Name | Description |
|---|---|
| api:(NSString *)method | Call raw player API method. |
| play | Plays the video. |
| pause | Pauses the video. |
| togglePlay | Toggle the play stat of the videos |
| load:(NSString *)video | Load another video in the player by specifying its id. |