Monday, January 28, 2013

Few tips on ARC Compatibility - enabling/disabling your project ARC

Most of you guyz already know what really  ARC means, but for rest of you which are unknown about it, ARC means Automatic Reference Counting, is a feature of the new LLVM 3.0 compiler and it completely replaces the manual memory management that means we do not have to worry about memory releases of the objects we create. ARC has removed the use of retain, release, autorelease keywords and it acts like a garbage collector. ARC will take care of all the memory issues, and we developer do not have to worry about it any more.


PROBLEM :
However, since ARC is a new feature in iOS development , we may find compiling errors regarding memory keywords  while we want to mix up old projects with new ARC enabled ones, or  error occurs when we want to use ARC disabled  third party libraries to our ARC enabled project. Just like in pic:


Friday, January 25, 2013

Sending e-mail in background from iOS apps using SMTP gmail account

The iOS SDK has made it really easy to send email using the built-in APIs. With a few line of codes, you can launch the same email interface as the stock Mail app that lets you compose an email. You can pop up mail composer form , write message and can send plain mail or file attached mail using MFMailComposeViewController class. For more info : Sending e-mail from your iOS App

But, in this section what i am going to explain is about sending emails without showing the mail composer sheet ie. sending emails in background. For this feature, we can not use iOS native MFMailComposer class because it does not allow us to send emails in background instead it pop ups the mail composer view from where user have to tap "send" button , so for this section i am going to use  SKPSMTPMessage Library to send emails in background, however email account has to be hardcoded on this method.

Limitations :
1. sender/receiver email address has to be hardcoded or you have to grab it using some pop up form in your app where user inputs sender/receiver email address. In addition, sender account credentials has to be also hardcoded since there is no way we can grab it from device settings.

Method :
1. Import CFNetwork.framework to your project.
2. Include     #import "SKPSMTPMessage.h"
                    #import "NSData+Base64Additions.h" // for Base64 encoding
3. Include <SKPSMTPMessageDelegate> to your ViewController
4.  Download SKPSMTPMessage library from  
                                             https://github.com/jetseven/skpsmtpmessage
5. Drag and Drop "SMTPLibrary" folder you have downloaded to your project.

  Before proceeding, let you know that i am using sender/receiver email address and sender password hardcoded in the code for this example.But, you may grab this credentials from user, allowing them to input in some sort of forms(using UIViews).

Friday, January 18, 2013

Integration of File Sharing from your App to iTunes

Hey guyz, in this section i will be explaining about how we can share app's files which are stored in its document directory  via itunes, say, accessing app's document directory. For example, lets say some app named "testApp" stores bunch of files in its documents folder which are downloaded from web, now we may want to see those files in our desktop. So for file sharing, iOS 4 & later have a great new feature called File Sharing that provides a convenient way for users to transfer files between their computer and your app.

Its really a simple step and it goes like this.......
- To enable File Sharing in your app, you simply set the boolean flag UIFileSharingEnabled in your info.plist. Or , some of you may find Application supports iTunes file sharing flag in your info.plist. Just set flag to YES.


After that, iTunes will display anything you save to the Documents directory in your app to the user, when they go to the “Apps” page in iTunes like this :
Note : One thing, you must keep in your mind is that only the files that are stored in your app's documents directory can be seen and shared!!! For storing files in documents directory, please have a look at :  Handling NSDocumentDirectory of iOS App

That's all from Xcode side, Now for more details on  File sharing features : http://support.apple.com/kb/HT4094#

Thursday, January 17, 2013

Checking Internet Connection in iOS Apps

In this section, i will be describing about how we can check internet connectivity in iOS apps. For this kind of task, Apple has provided a very helpful sample reachability class . So, we will be using that class to make it working on our apps. First , grab the reachability sample code from: http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

Now, you don't have to ho through all the codes in sample app, just follow these few steps to check internet connection in our app :

  1. Add the SystemConfiguration.framework to your project.
  2. Add the files Reachability.h and Reachability.m only from the Reachability sample code you just downloaded to your project.
  3. Add the following code in the implementation file where you need to test the Internet connection.