Monday 19 December 2011

Beginning Twitter integration iOS 5: Part 1

iOS 5 came with a bang and with tons of surprises. 1500  new API, sounds very interesting.

One of the good thing is that  iOS 5 ships with the Twitter framework. So it means no hectic code, oauth implementation by the developer. All of it is done and taken care by this framework.
And the best part is that it supports multiple accounts.

So Today we gonna sneak peak in this framework and will implement a simple twitter Application that will be sending  your tweet.

Get Started
As we are using new feature of iOS 5, so i am assuming that you have Xcode 4+.

> Fire up your Xcode and name the project as LetsTweet.
Make sure that ARC(Automatic reference counting) is enabled.

>Select the Single View Application.

Adding Twitter Framework

This is accomplished by clicking on your project in the Navigator sidebar, selecting your project’s target, and going to Build Phases. This should pull up a table with a few items. Click the arrow next to Link Binary With Libraries to expand the options and click the + button to add a new library. Find the library named Twitter.framework in the popup menu and select add button.
In the end it will be like:



As we are only going to implement the very basic functionality i.e to tweet, So our view controller will be simple too.

> Now go to your ViewController.xib, drag a UIButton to the View, and edit the text on it to be Tweet.



> Click on the file ViewController.h, here we are going to declare a function that will handle the tweet button click.

> In your ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
    
    
}

-(IBAction)letsTweet: (id) sender ;

@end



> Now connect the function "letsTweet" to Sent events (Touch up) of tweet button.


> Lets program the ViewController.m file.

For using the Twitter framework you have to import it to your Class.

so include this 

 #import "Twitter/Twitter.h"

So in your .m file implement the  -(IBAction)letsTweet:(id)sender function as below.

-(IBAction)letsTweet:(id)sender {
    //Create the tweet sheet
    TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
    
    //Customize the tweet sheet here
    //Add a tweet message,
    [tweetSheet setInitialText:@"This is iOS Muncher sending first tweet. :)"];    
       
    
    //Set a blocking handler for the tweet sheet
    tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result)
    {
        [self dismissModalViewControllerAnimated:YES];
    };
    
    //Show the tweet sheet!
    [self presentModalViewController:tweetSheet animated:YES];
    
}


Lets understand the code:

1.  TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController allocinit];

This allocates a new tweetSheet for us, this is the in-build ViewController that will be seen when you tap on tweet button.

2.   [tweetSheet setInitialText:@"This is iOS Muncher sending first tweet. :)"];

We can set initial text for the tweet, you can edit it later also when you are on the tweetSheet.

3.   tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result)
    {
        [self dismissModalViewControllerAnimated:YES];
    };

Here we have to set a blocking handler for the result. This is to ensure that we don’t mess up the rest of the app while tweeting until we dismiss the modal view (that is our tweet sheet)

4. [self presentModalViewController:tweetSheet animated:YES];

This shows up your tweet sheet.


Running the Application:

Hit Build and Run button, you will the see the app running in your simulator.

Tap on tweet Button. If you see this screen as below, dont panic.


All iOS 5 devices have a feature in their setting page, where user can set their twitter account.
You have to set the account only one time, and it will not ask you again and again to authorize while posting tweets. cool ha..!!

> Just click on settings and add your twitter account.


>After adding your account. Launch the App again and just tweet.




So you are ready to send your own tweet from your own App.

There are lots customization that you can do with this framework, like you can tweet pictures, url, can see your friends tweet, search something on twitter,get tweets from particular accounts and lot more.

Well this was just a basic, in the coming post we will fully customize our LetsTweet Application

Stay Tuned.. :)





Friday 16 December 2011

All you need to know about RhoMobile


 Rhomobile, selected Best Startup at Interop 2009, lets developers use HTML and Ruby to create native iPhone, BlackBerry, Windows Mobile, Symbian, and Android applications.  
       
Rhodes is a free and open source MVC-based framework written in Ruby under the MIT license for building native cross-platform mobile development applications. Rhodes enables developers to harness their traditional web skills such as HTML, HTML5, CSS, and JavaScript, instead of in Objective-C or other complex native device OS language, to create a native app, and porting the app in cross operating systems such as Android, Apple’s iPhone and iPad, BlackBerry, Windows Mobile, Symbian and HP/Palm's Linux-based WebOS.

These native device applications leverage device capabilities such as GPS, accelerometer, Multimedia, PIM(Personal Information Management) data, Bluetooth, geolocation, camera, native mapping, push notifications, alerts, calendar, barcode reading, jQTouch and signature capture in app.


RhoSync is the fastest and most scalable sync server produced by Rhomobile that enables access and edit data irrespective of connectivity. RhoSync is useful for mobile apps dealing with data from a web app that requires a two-way sync with offline activity support. RhoSync 2.0 is optimized to automatic synchronization of backend enterprise app data to the mobile device.

RhoHub is a Rhomobile service for mobile applications that integrates Rhodes platform and RhoSync, a standalone sync server for enterprise data. RhoHub is the first development-as-a-service offering that allows developers to deploy mobile application apps, builds, and sync servers to the cloud across multiple smartphone operating systems. RhoSync server provides faster access to synced local data and optimized native styling for all smartphones. It also offers easy access to offline and disconnected data for the users of applications.  iPhone developers can leverage the RhoHub RhoSync server to test and deploy sync-enabled Rhodes applications.

RhoGallery is Rhomobile’s Enterprise App Store that offers enterprise mobile app management solution. RhoGallery provides easy access for employees to provision mobile apps on their smartphones and easily manage it with updates.

Rhodes developer 
Rhomobile allows Rhodes developers to leverage their existing web skills using HTML to create powerful native Rhodes mobile apps that work across all major smartphones, Leveraging the latest technology, standards and best practices in Rhodes development, our proficient Rhodes developers are highly committed and proficient in Rhodes programming language to build mobile applications that have a native look and feel.  
Rhodes framework allows developers to build mobile applications with HTML and Ruby rather than Objective C across cross-platform OS such as iPhone, Blackberry, Windows Mobile, Symbian, and Android. Our team of dedicated Rhodes developers can build and deploy mobile apps in multiple operating systems. Our skilled Rhodes mobile developers can develop native applications that access and create events in its native device calendar, with Bluetooth connectivity to their apps.


Features of Rhomobile:

1.  Portability-  write once, deploy on all major devices.
2.  Enterprise Security Compliance- Use Rhomobile’s secure model to secure your mobile solutions from end to end.
3. Dead Simple App Integration- Easily extend your backend web services to native clients.
4.  Synced offline Data- Give end users the ability to use apps with or without a connection through their own local copy of data.
5. Native Access-  Exploit the native device capabilities such as: GPS, PIM Contacts, Camera, etc.
6. App and Data Management: Easily provision and manage apps and data to your end users, including an ability to remotely wipe apps and data.


My Opinion:
Building an application using rhoMobile can be done easily using HTML and javascript, But to support the MVC architecture Ruby to be used.
RhoMobile is very good for the application that are Data Centric. 
RhoMobile has a great support for all major mobile platforms. The only problem is here learning Ruby, well but that can be resolved too, As learning a new language is always fun.
The other problem is that the cost issue as mentioned above creating a simple app is of no charge, but for enterprise based application will cost Commercial Licenses of Rhodes, which includes updates and commercial grade support for one year, is available for $1,000 per app for an unlimited number of users.





Running Appcelerator project in Xcode.


 Couple of days earlier, I was more busy in finding the best mobile framework suitable for building iOS Apps, without diving into native code.

I came across this Appcelerator Titanium. I found this pretty interesting, But searching for while I could not found that how it could be beneficial for an iOS developer like me.

I was more interested in running the appcelerator project in Xcode. After juggling for a while I managed to do that.
Lets start Munching:

Step 1:  Download the Titanium Studio from : http://www.appcelerator.com/products/titanium-studio/

Now install it on your Mac.

Step 2: Launch the Titanium for the Application folder.
Below is the Titanium IDE



Step 3.  Now Go to File>New>Titanium Mobile Project.

You will see the similar screen as below:


Step 4: Click on Next , Here you can either choose a pre-build template or can go without a template.
























I have selected the Geolocation mobile client template.

Step 5: Hit Finish and you are done.

What you see now is your project in the IDE. On the left pane double click  to the tiapp.xml file.
It will open it for you in the right pane.
This is where you do your project settings, below is the similar screen that you will get.


As you can see under the Resource folder you have your app.js file, which is the main file where you code your javascript.


As you can see on the right side  you have TiApp Editor open and you have your "MyFirst App settings in front of you".

The beauty of this Appcelerator is that you code only once and can deploy for iPhone,iPad,Android, Mobile web.


We are not diving into the programming but as we have selected the GeoLocation mobile client template. Lets see what this template has done for us.

Lets build this project

In between the toolbars you can see the Run button. Click on the small arrow next to it.














>Select the option Run Configurations.

You will see the below screen. Select the Project that you wan to run, for us is MyFirstApp.
Choose the iOS SDK as 4.0 or above not SDK 5 (As for me while choosing iOS SDK 5 it gives error).

After doing this, Click on the Run button.(bottom right)
































> You can see all the logs in the bottom console window.

Now when the build done. You might be thinking that where is the Xcode in this.

I will say here comes the Xcode.

Navigate to the workspace directory that you set while installing or running the Titanium studio.
The path will be like.

yourWorkspaceFolder>MyFirstApp>build>iphone>MyFristApp.xcodeproj

So this is your Xcode project file.
Run it and it will open the Xcode for you.

> Now you have your favorite IDE Xcode in front of you and a project loaded in it.
Then what are you waiting for hit the Build and Run button

Below is what you will see.























> So you can see that we have only used a single template for Geolocation and we have this beautiful app showing your current location. (dont worry simulator does not show the actual location, it will always show the Apple headquarters) 


Final Words:


You can build a whole app using Titanium Studio using just JavaScript.(good for web developers) and can deploy it to the various mobile devices.

If you want to extend your project using the native language i.e using Objective-C, then you have to write modules and then attach it to your existing project.

Here is a tutorial link for that iOS module Development

Pages