Mobile Line Of Business

Richard Jones (MVP)

  Home  |   Contact  |   Syndication    |   Login
  202 Posts | 0 Stories | 36 Comments | 0 Trackbacks


Welcome to the Mobile Line Of Business Blog

Tag Cloud

Article Categories


Post Categories

Image Galleries



This is cool!   I just got an Apple Watch App.  getting results live over the Internet from an oData database.   All realtime, and working really quickly.   Here’s how it works….

So using the following code in an Apple Watch app.

WKInterfaceController.openParentApplication(ourmsg, reply: { (replyValues, error) -> Void in dispatch_async(dispatch_get_main_queue(), { self.populate(replyValues) });

This makes a call into my iPhone app. which makes an oData request.

The results then come back and populate a table using a callback to main thread.

The iPhone app, has a very simple bit of code that responds to the watch request and looks like -

func application(application: UIApplication!, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!, reply: (([NSObject : AnyObject]!) -> Void)!) {
var xx = Core().oDataQuery("Categories")
xx.invoke { (ret, error,status) -> () in
if error == nil
if var returndata:NSArray = ret
var ourreply=["Data":returndata]

Final bit of code, is the stuff to populate the Apple Watch table
func populate(ret:[NSObject : AnyObject])

if let records=ret["Data"] as? NSArray

self.tvourdata.setNumberOfRows(records.count, withRowType: "default")
// Iterate over the rows and set the label for each one.
for var i = 0; i < records.count; i++
// Get the to-do item data.
if let record = records[i] as? NSDictionary

if let row = tvourdata.rowControllerAtIndex(i) as? OurRowController
var label=record.valueForKey("CategoryName") as String row.lblname.setText(label)


posted on Sunday, January 18, 2015 2:15 PM