All Things CC:

All things Commuication & Computing….

Archive for the ‘IOS Development’ Category

How to learn XML, HTML or for that matter anything in Programming

leave a comment »

Over the last several years I continued to buy books on XML and HTML, and all of them went unread. This year I did end up learning both XML and HTML but NOT by reading books but by programming. In my recent hacking & prototyping projects with IOS and OSGi I had to use XML and HTML to exchange information between devices. I had to read and learn how to use NSXMLParser in IOS, it came with an excellent companion guide – “Introduction to Event-Driven XML Programming Guide for Cocoa” which was useful reading. I leveraged the hpple XML parser. Note the real learning came from my own programming, not from the tutorial or examples from books or websites. The real trick to learning XML and HTML was to understand how they are defined by observing the code working, iterating through several failures before I met with success. 

My 2c – yes read a programming, follow tutorials and examples from websites but the real learning comes when you embark on your own project! 

 

Footnotes:
– Google Search, Stack Overflow, Github and many other sites also serve to accelerate your learning only if you understand the solutions put forth by the community and adapt it to your own project. Blind copying never helps!
– Github is awesome!!!
– hpple is a great resource, I learnt the basics from the Ray Wenderlich tutorial: How to parse HTML on IOS by Matt Galloway 

Written by Ashu Joshi

August 19, 2012 at 6:32 pm

SSDP Service/Device Discovery [Part 2, ROM]

leave a comment »

To begin my project – a Remote OSGi Manager (ROM) as described in my first part here, the first task I picked up was to try developing  a very rudimentary app that would discover the RTCOA Thermostat using the SSDP protocol. As you can see from the screenshot – it is really rudimentary user interface but my focus was to get my MVC right, and more importantly get the network interface going for the project. [BTW if you observe carefully – you can see the “Marvell” code that has been used in the RTCOA Thermostat].

 

 

Screen_shot_2012-04-10_at_6

 

After much searching and reviewing samples, I decided to go with the Cocoa Async Sockets, and I have ended up using them for all of the network interface in my iOS/iPad app. I got started with the AsyncUdpSocket to leverage it for running SSDP based discovery of the RTCOA Thermostat. The screenshot above was the start. I took the SSDP objects (serviceSSDP.m, serviceSSDP.h) and moved them to the bigger project. Also as a first step – the SSDP discovery code stopped after discovering the first controller. Given that in my project I was going to support multiple controllers, I ended up modifying the code to take into account that I should be able to discover multiple controllers (or devices) and then add them to a NSMutableArray.

 

 

//
//  serviceSSDP.h
//  SimpleSSDPDiscovery
//
//  Created by Ashu Joshi on 3/1/12.
//  Copyright (c) 2012 Movinture, LLC. All rights reserved.
//

 

#import <Foundation/Foundation.h>
#import “AsyncUdpSocket.h”
#import “connectedLifeController.h”

 

@interface serviceSSDP : NSObject

 

// This is the string that is Multicast to Discover the Controller
@property (strong, nonatomic) NSString *discoverControllerString;
// The Controller would respond with the string below upon discovery being received
@property (strong, nonatomic) NSString *responseStringFromController;
// The list of discovered controllers
@property (strong, nonatomic) NSMutableArray *controllerList;

 

@property (strong, nonatomic) connectedLifeController *currentController;

@property (strong, nonatomic) AsyncUdpSocket *ssdpSocket;

 

– (BOOL)startControllerDiscoveryProcess;

– (BOOL)startControllerDiscoveryProcess:(NSMutableArray *)listOfControllers;

@end

 

Once I got the Thermostat to discover using SSDP discovery code using iOS/iPad, I turned my attention to the Plug Computer. I created the framework for my bundle (OSGi terminology for an application). And the first thing I did was to implement code built out code in Java to run a SSDP “advertise” service on the Plug Computer. Before even migrating or trying the code on the Plug Computer I tried the code on my PC/Mac using Eclipse, once it was working I migrated it as a bundle/service in the OSGi framework on the Plug Computer. This code uses threading so that it is always running on the Plug Computer.

 

In the next part I will give an overview of the Java/OSGi code and the network interface implemented….

Written by Ashu Joshi

April 10, 2012 at 7:46 pm

Getting Started: IOS-based OSGi Application Manager

leave a comment »

I am going to provide more details on the project that I have in of the earlier posts. The objective of the project is to build a network interface between an iOS application & a device running OSGi (it could be any device running OSGi since that lends to portability but I am going to start with a Plug Computer). And using that network interface/protocol  the IOS/iPad application would function as a “Remote Manager” to the Plug Computer. Obviously all code on the Plug that interacts with the iOS/iPad app would be developed in OSGi/JVM.

I had started doing some preliminary design work and thinking through in late January, and to prepare spent last two weeks of December (2011) getting my coding skills comfortable with both Java & iOS/Objective-C. The approach was to build the project incrementally, baby steps at a time. The key was to define the network protocol/interface between the iOS App & Plug. The interface by itself was very simple but I had to decide what it would do and more importantly in the first iteration what it won’t do.

Here is a simple diagram illustrating the protocol/interface, and I had decided to use a Sockets Interface between the iOS and Plug. The Plug and the iPad are both on the same network/subnet.

Image001

Using sockets was my first decision – in my next iteration I would move to a REST API between the two. I can comfortably say 3 months into it that the design & implementation is flexible enough where my “network interface” code on both sides is separate from the actual command processing. The next couple of decisions were also what not to take on in the first round of implementation – no TLS/SSL sockets and no authentication. I would take that on once I have the entire interface working. In addition there is no authentication or provisioning for the iPad/iOS app – that is – I have not built in any authorization check before the iOS/iPad app would be allowed to access the OSGi information on the Plug computers.

Written by Ashu Joshi

April 7, 2012 at 5:31 pm

iOS Programming: Getting Started, & Sticking To It

leave a comment »

Search the web and you will turn up gazillions of resources on getting started with IOS Programming, and I have done the same. In fact for the last three years I have been spending $99 every year paying for the IOS Developer Subscription and buying books. Apple keeps on revving (albeit not at the same rate as Android) the IOS SDK, APIs and the books that I had bought kept getting obsolete! I tried attending local Meetups and trying sample code. All I was able to do was to or rather hack together a few apps that could control or manage a Set Top Box (STB) using iTouch or iPhone. And the user interface on them was horrible…

Finally last December as I became more engaged and serious I latched on to three critical resources, here they are and the challenges with them:
As a prerequisite to all of the above – you need an Intel-based Mac, I had access to my personal iMac and you need to have the IOS SDK. While the SDK is free, having the $99 membership is required to test with an IOS device [you can get started testing with the IOS Simulator which is part of the free SDK and it is very, very good]. Testing on IOS device, IMHO, is very important. But not having one should not prevent you from getting started, it is however a challenge to keep going and be good at it.

Now, based not the version of the OS (Leopard, Snow Leopard, Lion) on the Mac machine you have and the version of SDK you will have to work around and adapt to a few new concepts and technologies introduced by Apple chief among them being “ARC” (Automatic Reference Count) – which reduces the burden not the programmer by making memory management a linker feature. And on that note – you may want to get the 3rd Edition of the IOS Programming mentioned above because the 2nd Edition is pre-IOS 4.3 SDK and that does not support the ARC. This, for a beginner, will add to the confusion of getting started.

You can use the resources above or something else, but the key to success is finding a project of your own that will help you apply the lessons. And as you build your own application or work on your own project Google Search is indispensable, and I would highly recommend Stack Overflow as well.

Written by Ashu Joshi

April 2, 2012 at 11:44 am

Posted in IOS Development

Tagged with