General information

Github repository: ok-ios-sdk

iOS application with OK SDK example: ok-ios-sdk-examples

iOS SDK to authorize users via client authorization, publish new posts, invite friends to a game, send notifications and invoke REST methods.

Setting up

Before using SDK you need to be sure everything is configured correctly for your app:

  • iOS platform is added to your app’s platforms list;
  • client authorization is enabled;
  • redirect_uri ok{APP_ID}://authorize is added to redirect_uri’s list;
  • application has all required API permissions. It is recommended to have LONG_ACCESS_TOKEN permission enabled for native apps.

To enable SDK do the following:

  • add SDK files to the project, i.e. as git submodule
  • update Info.plist according to the example
    • add ok{APP_ID} and okauth schemes
    • add following code block
  <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
	
  • update didFinishLaunchingWithOptions method in AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    OKSDKInitSettings *settings = [OKSDKInitSettings new];
    settings.appKey = @"{APP_KEY}";
    settings.appId = @"{APP_ID}";
    settings.controllerHandler = ^{
        return self.window.rootViewController;
    };
    [OKSDK initWithSettings: settings];
    return YES;
}
  • add method openURL to AppDelegate
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    [OKSDK openUrl:url];
    return YES;
}

SDK usage example

Authorization (authorizeWithPermissions)

[OKSDK authorizeWithPermissions:@[@"VALUABLE_ACCESS",@"LONG_ACCESS_TOKEN"] 
	success:^(id data) {} 
	error:^(NSError *error) {}
];

REST method invocation (invokeMethod)

[OKSDK invokeMethod:@"METHOD_NAME" arguments:@{} 
	success:^(NSDictionary* data) {} 
	error:^(NSError *error) {}
];

Publish / invite / suggest widgets (showWidget)

[OKSDK showWidget:@"WidgetMediatopicPost" arguments:@{@"st.attachment":@"{\"media\":[{\"type\":\"text\",\"text\":\"hello world!\"}]}"} options:@{@"st.utext":@"on"} 
	success:^(NSDictionary *data) {} 
	error:^(NSError *error) {}
];

[OKSDK showWidget:@"WidgetInvite" arguments:@{} options:@{} 
	success:^(NSDictionary *data) {} 
	error:^(NSError *error) {}
];

[OKSDK showWidget:@"WidgetSuggest" arguments:@{} options:@{} 
	success:^(NSDictionary *data) {} 
	error:^(NSError *error) {}
];