iOS Tutorial - How to add ADNKit to your iOS project! (Part 2)

If you followed the previous tutorial then proceed with this tutorial to create a simple app that will post to your ADN feed.  

If you DID NOT follow the previous tutorial, this tutorial may not help out as much, but feel free to use it too.

 

Step 1.) Import the ADNKit headers

Make sure you import the ADNKit headers into where you will be using the ADNKit.

Should look something similar to:

 

Step 2.) Load your access token

If you didn't get an access token yet, go to Dev Lit to get an access token to use for this example.

With the access token, inside of your 

- (void)viewDidLoad

 load it like so:

  1. - (void)viewDidLoad
  2. {
  3. [super viewDidLoad];
  4.  
  5.  
  6. // Load the access token from Dev Lite
  7. [ANKClient sharedClient].accessToken = @"YOUR ACCESS TOKEN GOES HERE";
  8.  
  9. }

Step 3.) Create a button that will send your post

In the project storyboard, drag a button object onto the view. Give it whatever text you would like. Then create an action for this button in your view controller, so that when this button is touched, it will send a post to your app.net feed.

 

Step 4.) Creating your "post"

Inside of your button's action function, add the following code:

  1. ANKPost *post = [[ANKPost alloc] init];
  2.  
  3. post.text = @"Hello, world!";
  4.  
  5. // Create the post and send it
  6. [[ANKClient sharedClient] createPost:post completion:^(id responseObject, ANKAPIResponseMeta *meta, NSError *error) {
  7. if(error == nil) {
  8. // Display this message in the console if the post was successful.
  9. NSLog(@"Posted to app.net.");
  10. } else {
  11. // Display this message if there was an error when posting.
  12. NSLog(@"Post was not posted.");
  13. }
  14. }];

Step 5.) Run it!

Run your app. When you click on the button, it should post "Hello, world!" to your app.net feed!