Developer

HttpConversation Workflow

Add HttpConversation to your iOS project.

Context

To complete this flow, you must obtain the iOS Native Client SDK libraries, which are available as part of the SAP Mobile Platform Client SDK Installer. HttpConversation is shipped in form of separate artifacts such as:
  • Statically linked libraries
  • Resource bundle folders
  • Public header files

Before you can use HttpConversation, you must add associated artifacts. You also need to add dependent frameworks and configure your build settings. If you are working with an existing project rather than creating a new one, the steps may differ.

To trigger a network request with the HttpConversation libraries, you can use this simple logic. In your project, you would centralize the network handling and separate it from the UI handling. This procedure shows how to code the simplest GET request to a public endpoint on the Web. The endpoint is not protected, so there is no authentication challenge.

Procedure

  1. In Xcode, create a new project or open an existing one.
  2. Add HttpConversation artifacts to your project:
    • libHttpConversation.a
    • libHttpConvAuthFlows.a
    • HttpConvAuthFlows.bundle
    • Header files for the libraries
  3. Add artifacts that the HttpConversation library depends on:
    • libClientLog.a
    • libE2ETrace2.a
    • libSupportability.a
    • libPerformanceLib.a
    • Header files for the libraries
  4. Select your project from the Project Navigator, and choose your application's target.
  5. Open the Build Phases tab, and within Link Binary with Libraries, add these frameworks:
    • Security.framework
    • libsqlite3.dylib
  6. Choose your project, rather than a specific target, and open the Build Settings tab.
    1. In the Other Linker Flags section, add -ObjC and -all_load. If these settings are not visible, change the filter in the Build Settings bar from Basic to All.
    2. In the header search path section, adjust the path to look for public header files. Depending on where you copied the header files, the path string should look something like this:
      $(PROJECT_DIR)/includes/public/**
    3. In the library search path section, adjust the path to look for the binary files. Depending on where you copied the library files, the path string should look something like this:
      $(PROJECT_DIR)/libraries/$(BUILD_STYLE)-universal/**
  7. Add the HttpConvAuthFlows.bundle to your project.
  8. Open the main UIViewController and add code.
    1. Import statements, constants, and IBOutlets:
      #import "ViewController.h"
      #import "HttpConversationManager.h"
      #import "CommonAuthenticationConfigurator.h"
      
      #define URL @"http://services.odata.org/V3/Northwind/Northwind.svc/"
      
      @interface ViewController ()
          @property (weak, nonatomic) IBOutlet UITextView *result;
      @end
      
      @implementation ViewController {
          HttpConversationManager *conversationManager;
      }
      
    2. In the viewDidLoad method of the UIViewController, initialize an instance of the HttpConversationManager:
      - (void)viewDidLoad
      {
          [super viewDidLoad];
          //create instance of default configurator
      	CommonAuthenticationConfigurator *configurator = [[CommonAuthenticationConfigurator alloc] init];
          //set the parentView property to the currently presented ViewController
          configurator.parentView = self;
          //init an instace of the HttpConversationManager
          conversationManager = [[HttpConversationManager alloc] init];
          //configure the HttpConversationManager with the default configurator
          [configurator configureManager:conversationManager];
      }
      
    3. Connect an IBAction from the storyboards UIButton and implement the request sending in it:
      - (IBAction)doConversation:(id)sender {
          //Create a new NSMutableURLRequest
          NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[[NSURL alloc] initWithString:URL]];
          //execute the request with the conversation manager
          [conversationManager executeRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
              //process the response data
              NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
              NSLog(@"got response: %@", responseString);
              dispatch_async(dispatch_get_main_queue(), ^{
                  [_result setText:responseString];
              });
          }];
      }