Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
0 Kudos

Hi everyone!

I have great news...

Loads of How-To-Guides have been published. Hope these documents will help you to learn what has been discussed in the previous blogs even quicker and efficiently.

They are surely covering essential topics for both online and offline stores. In addition to it, it covers following topics:

- User Onboarding without MAF UI

- Push Notification

- Batch Request with Online Store

- Log & Trace

Together with the H2Gs, the associated Xcode projects are all ready for you. It has a set of Exercise (the one you can go through with H2G step-by-step instruction to complete) & Solution (completed one - it will run by adding the required SDK libs). In the Github UI, "master" indicates Exercises and "solution" does Solution Xcode projects.

Perhaps I should address a few tips, which are demonstrated in the example Xcode projects.

Reloading TableView & Showing Alert in the Main Thread

After you fetch the data, the second thing you would do is to render the data via a table view or popup. Have you encountered a strange situation where the data fetch works pretty fast but after the data retrieval, it takes a while to invoke table view to render…?

You have to make sure if you're calling it in the main thread. You can google the detailed general discussion but in a nutshell, here's a tableView example:

01  [tableView reloadData]; // normal way
02  // calling it in the main thread
03  [tableView performSelectorOnMainThread:@selector(reloadData)
04                              withObject:nil
05                           waitUntilDone:NO];
06  // alternative way to call it in the main thread
07  dispatch_async(dispatch_get_main_queue(), ^{
08    [tableView reloadData];
09  });

By calling it in the main thread, you can confirm the runtime speed boosts up. The same story goes with other UIs such as alert.

01  [alert performSelectorOnMainThread:@selector(show)
02                          withObject:nil
03                       waitUntilDone:NO];

How come we have to do this? This is not really OData SDK remark but a general iOS tip. Apple's API reference says:

"Note: For the most part, use UIKit classes only from your app’s main thread. This is particularly true for classes derived from UIResponder or that involve manipulating your app’s user interface in any way."

OData SDK's HttpConversationManager does not call back on the main thread, so the SODataStore also call back on a background thread. It’s the task of the app developer to take care of proper UI calls in the way explained above. The NSURLSession also calls back on a background thread.

Conclusion - Always call UI in the main thread! 😉

OData Format in either JSON or XML

By default the online store handles OData in XML. Here's how you switch it to JSON format. As JSON is far lightweight than XML, you would like to go with JSON - but you might want to use XML during the development, as it would be easier to debug if something went wrong.

01  // Use options to configure the store to send the request payload in JSON format
02  SODataOnlineStoreOptions *storeOptions = [[SODataOnlineStoreOptions alloc] init];
03  storeOptions.requestFormat = SODataDataFormatJSON;
04  onlineStore = [[SODataOnlineStore alloc] initWithURL:[NSURL URLWithString:endpointUrl]
05                               httpConversationManager:httpConvManager
06                                               options:storeOptions];

The offline store only sends modification requests in JSON format. The server component can perform refreshes in either XML or JSON, but the default is JSON - Just about every OData producer supports JSON nowadays.

MAF UI Redirects to Afaria Client App

If you're deploying the app in your iOS device, you would notice the MAF UI redirects to Afaria Client App, every time you onboard. The context switch happens as MAF UI checks if Afaria provides configuration for the particular application. This could be annoying if you haven't configured Afaria - here's how to turn off the default context switch behavior.

1. Find the "MAFLogonManagerOptions.plist" in the bundles folder of OData SDK libs in the Xcode project.

2. Switch the "keyMAFUseAfaria" value to NO.

3. Make sure there's "MAFLogonManagerNG.bundle" in Copy Bundle Resources in Build Phases tab in Xcode project. If not - add it.

That's all, happy learning with H2G 🙂

See you in the next blog,


List of blogs