Skip to Content

/wp-content/uploads/2014/12/13_598401.pngHi 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.

/wp-content/uploads/2014/12/github_598412.png

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.

/wp-content/uploads/2014/12/mafoption1_598628.png

2. Switch the “keyMAFUseAfaria” value to NO.

/wp-content/uploads/2014/12/mafoption2_598629.png

3. Make sure there’s “MAFLogonManagerNG.bundle” in Copy Bundle Resources in Build Phases tab in Xcode project. If not – add it.

/wp-content/uploads/2014/12/mafoption3_598630.png



That’s all, happy learning with H2G 🙂



See you in the next blog,

Ken


List of blogs

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

    1. Kenichi Unnai Post author

      Confirmed. Seems the folder is still there but the attribute is set as private now. I’ll check with colleagues, it should get back soon.

      (0) 

Leave a Reply