">mixi Developer Center (mDC)

mixi Connect

mixi Connect (English) » mixi Graph API » mixi API SDK for iOS » Initialization and authorization process

Initialization and authorization process

This section describes how to write code when developing applications that use the mixi API SDK for iOS.

Adding the header files

If you use the SDK, please import the following header file.

#import "MixiSDK.h"


The mixi class used to call mixi API is a singleton class. You can get the instance as follows.

[Mixi sharedMixi]

However, you must initialize the singleton instance before using the API. For instance, when you use the Graph API, in the method UIApplicationDelegate#application:didFinishLaunchingWithOptions: you can use the following code. (Please change all the parameters to match the settings of the application)

Mixi *mixi = [[Mixi sharedMixi] setupWithType:kMixiApiTypeSelectorGraphApi 
[mixi restore];
[mixi reportOncePerDay];

Notifying the start of application

Add the application starting notification code to applicationWillEnterForeground

- (void)applicationWillEnterForeground:(UIApplication *)application {
    [[Mixi sharedMixi] reportOncePerDay];

Adding the code below is optional. It will help mixi improve the service. No application-specific information will be sent to mixi.


To use the mixi Graph API, a user must be authorized prior to use. To display the screen for this, use the authorize: method.

[mixi authorize:@"r_profile", @"r_diary", @"w_diary", nil];

Calling this method generates a screen prompting the user to authorize use of the mixi official app.

By default, an authorization screen is chosen depending on the installation of the official application. You must add both of the following processing methods.

Authorization with the official application

When the official application is installed on a user's device, it is used for the authorization.

To receive the results of the authorization from the official application (such as an access token) , please add the following to the UIApplicationDelegate#application:openURL:sourceApplication:annotation: method.

NSError *error = nil;
NSString *apiType = [[Mixi sharedMixi] application:application openURL:url sourceApplication:sourceApplication annotation:annotation error:&error];
if (error) {
  //Handling an error
else if ([apiType isEqualToString:kMixiAppApiTypeToken]) {
  // Complete authorization
else if ([apiType isEqualToString:kMixiAppApiTypeRevoke]) {
  // Complete cancelling authorization
else if ([apiType isEqualToString:kMixiAppApiTypeReceiveRequest]) {
  // Receive a request

If the above authorization is complete, the singleton object holds the access token and the application is ready to use the API.

Authorization without the official application

When the official application is not installed on a user's device, the authorization screen embedded in the SDK is used.

The embedded authorization screen requires the parentViewController to be set. Add the code to UIViewController#viewDidAppear:.
- (void)viewDidAppear:(BOOL)animated
    [super viewDidAppear:animated];
    Mixi *mixi = [Mixi sharedMixi];
    mixi.authorizer.parentViewController = [self navigationController];
After the authorization, the view managed by the parentViewController will be reopened.

Checking the authorization status

Use the following method to check the current authorization status.


Typically, the authorization screen should only display the first API call. It is possible to skip subsequent displays of this screen if you first call the isAuthorized method. If authorized already, this method will return YES. If not approved, NO will be returned.

Cancelling authorization

You can call the following method to cancel the authorization status. To protect users, be sure to implement this authorization cancel function when you use mixi API SDK for iOS.