Tuesday, July 16, 2013

Programmatically detecting isDevice iPhone 5 ?


Define global  condition as below in your global classes:

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

Used C functions:
DBL_EPSILON = will give the smallest value that will make a difference when adding with one.  Smallest number such that 1.0 + DBL_EPSILON  != 1.0.
fabs = gives absolute value of x (a negative value becomes positive, positive value is unchanged).

Now simply you can detect iPhone 5 as :
if(IS_IPHONE_5){
            NSLog(@"I am iPhone 5");
}
else {
              NSLog(@"I am not iPhone 5");

}

Monday, July 15, 2013

Auto Search/Auto Complete using UITextField as SearchBar for iOS app


After a long gap, I made a time off  from my regular stuffs to write here few things. This time I choosed a topic  “Auto Search/Auto Complete” ,. You guyz already knew about this feature , if not, then auto search/Auto complete is the process of searching when you type some character in Search field. Auto search simply detects each of the character you type and starts searching. Moreover, When a user is entering data into a text field, it’s often nice to have the ability to auto complete with custom values based on what the user is entering, saving their time.

Auto Search  the name,  always sounds complicated  . Even I always thought doing auto search features in iOS app must be complicated but I was wrong . It is not hard as it sounds, and how I figured it out , I am explaining here with simply using UItextField and its native method.

Here are the step by step guidelines :

1.     First thing you need to create is UITextField which works as a search bar and UITableView for displaying your search results. And another thing is data source (Array/Dictionary) which has a collection of data from where we need to search  based on the name/strings which user types in text field.
2.     You can play with UItableView  in your own way. You simply can hide it first and when starts searching and finds result , you can unhide the table and reload the data. OR simply you can only add table view when search starts and remove it when we are done with the selection.
Here, I am using Hidden property of UItableView.
3.     Create UITextField , define <UITextFieldDelegate> in you .h file

Tuesday, April 23, 2013

Creating Watermarked Images from iOS app

Hello Guyz, In this section i will give you a bunch of code for creating a watermarked images. For example: Images with copyright text on top of it.  It sounds difficult but believe me, I have a really simple solution for you. In this part,  I am only merging  two of the images (one is watermark image and another is the image in which you want to put watermark) and hence making them one. So before we proceed, remember you should have watermark image and main image(picture) in your project resources.

-(UIImage *) generateWatermarkForImage:(UIImage *) mainImg{
      UIImage *backgroundImage = mainImg;
    UIImage *watermarkImage = [UIImage imageNamed:@"watermark.png"]; 

Wednesday, February 27, 2013

NSDocumentsDirectory and iCloud issue :preventing files in a App's Documents Directory being synced to iCloud

Many of you guys use app's  "Documents Directory" to store your files(image,video,pdf,music etc) in iOS app and being an iOS developer, it's obvious that you use documents directory since for each app,its the best way to store your files on the device permanently ,so that your app can  function properly in offline mode too.
However, if you are trying to store large number of files (obvious referring both in quantity and size) in app's documents directory, then i will say STOP & WAIT!!! 

- "STOP" because your app gonna be rejected by Apple because according to Apple's latest iOS Data Storage Guidelines : "Since iCloud backups are performed daily over Wi-Fi for each user’s iOS device, it’s important to ensure the best possible user experience by minimizing the amount of data being stored by your app." In summery i will say there are two points, every files in NSDocumnetsDirectory will be synced to user's iCloud and another is,if file sizes stored in NSDocumnetsDirectory are large then Apple will reject it since that causes the slow down on syncing process as iCloud-device syncs on daily basis.
-"WAIT" because i have a solution for it.
As pointed above if you are going to save files in NSDocumentDirectory then it will be back-up to iCloud,that means any thing you store in documents folder, will be synced to user's iCloud and will be publicly available. So if your files stored in documents directory  makes no sense by being public then you don't have to worry about anything(unless its size is bigger), but if your file  stored there are large in size and  can not be public,or i say if these files are only intended just for the scope of your app then you must have to do extra work to prevent from being synced to iCloud.

There are two solutions for it :

Monday, February 25, 2013

Sharing your app via Facebook and Twitter using Social Framework

Hello Guyz, in this section i will be describing about how we can use new "Social Framework" for sharing our app(tweet+status) from our iOS apps. It's really easy to deal with but, we should keep in mind that Social framework is only available from iOS 6 and later . Here, we will be only focusing on how to share our app , along with how to tweet and post a status from our iOS app.



1. Add "Social.framework" in your project.
2. Include  #import <Social/Social.h> to your .h file
3. Now, in your sharing method :

Tuesday, February 5, 2013

Ad-Hoc Distribution of iOS Apps - Simple Solution

If you are searching for a blog that describes the better way to do a ad hoc distribution of your iOS apps, I simply prefer you to go through : http://www.diawi.com/ 
This is the perfect way of distributing and installing iOS apps on real device. We don't need to sync app  through iTunes and even we do not need any computers, we can simply download it on our device and install it.

Note : Before proceeding, first make .ipa or .app file of your project from Xcode since in this section i am not talking about how to make .ipa/.app file from xcode but i am talking about how to send your apps to the end test users in a simplest and efficient way.

Best of Luck !!!

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.