Thursday, November 8, 2012

dispatch_once

dispatch_once is synchronous and its saying "perform something once and only once".It replaces the following:

+ (MyClass *)sharedInstance {
    static MyClass *sharedInstance;
    @synchronized(self) {
        if (sharedInstance == nil) {
            sharedInstance = [[MyClass alloc] init];
        }
    }
    return sharedInstance;
}
Advantage of dispatch_once is its faster.

Tuesday, November 6, 2012

#pragma mark


#pragma mark -
#pragma mark Initialization
Once this is in place, the Functions Menu (in the navigation bar) which shows a list of locations within a source file (e.g. definitions of classes, functions and methods) will display a new marker with the label "Initialization." 
The code in line 1 will add a line separator inside the Functions Menu, in this example, with the line appearing above the "Initialization" marker.
The figure that follows shows an example of how you might use #pragma mark to divide up various sections of your code.
Two notes:
  1. You cannot have a space after the "-" in the #pragma mark -
  2. If your code does not appear as expected (e.g. the separator does not appear), check that ‘Sort list alphabetically’ is not checked in the Code Sense preference settings.
courtesy:
http://macdevelopertips.com/xcode/xcode-and-pragma-mark.html

Monday, November 5, 2012

Getting device model number whether its iPhone 4 or iPhone 4S etc.,

We have to use C method since there is no NS method to get this information.
snippet of code goes like this:

#import <sys/utsname.h>
struct utsname *sysInfo;
int uname(&sysInfo);

    return [NSString stringWithCString:systemInfo.machine
                              encoding:NSUTF8StringEncoding];

The result should be:
@"i386"      on the simulator
@"iPod1,1"   on iPod Touch
@"iPod2,1"   on iPod Touch Second Generation
@"iPod3,1"   on iPod Touch Third Generation
@"iPod4,1"   on iPod Touch Fourth Generation
@"iPhone1,1" on iPhone
@"iPhone1,2" on iPhone 3G
@"iPhone2,1" on iPhone 3GS
@"iPad1,1"   on iPad
@"iPad2,1"   on iPad 2
@"iPad3,1"   on iPad 3 (aka new iPad)
@"iPhone3,1" on iPhone 4
@"iPhone4,1" on iPhone 4S
@"iPhone5,1" on iPhone 5
@"iPhone5,2" on iPhone 5
The structure utsname is declared in <sys/utsname.h> and has the following elements:
 char *sysname;
points to the name of the operating system implementation.
 char *nodename;
points to the node name within a communications network for the specific implementation.
 char *release;
points to the current release level for the implementation.
 char *version;
points to the current version number for the release.
 char *machine;
points to the name of the machine on which the operating system is running.

uname stores information about operating system you are running under in a structure pointed to by sysInfo.

 uname returns a nonnegative value if successful and a -1 if unsuccessful.
 The following example illustrates the use of uname to determine information about the operating system:

#include <systypes.h>
#include <sys/utsname.h>
#include <stdio.h>

main()
{
   struct utsname sysInfo;

   if (uname(&sysinfo) != -1) {
      puts(sysInfo.sysname);
      puts(sysInfo.nodename);
      puts(sysInfo.release);
      puts(sysInfo.version);
      puts(sysInfo.machine);
   }
   else
      perror("uname() error");
}

Refer:
1.http://support.sas.com/documentation/onlinedoc/sasc/doc750/html/lr2/zid-9810.htm
2.http://stackoverflow.com/questions/1108859/detect-the-specific-iphone-ipod-touch-model

CoreBluetooth Framework

http://www.icapps.be/corebluetooth-unraveled/
http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicsHome.aspx
http://stackoverflow.com/questions/12427718/ios-and-corebluetooth-low-energy-required?rq=1
http://stackoverflow.com/questions/12004171/bluetooth-4-0-with-older-bluetooth
Article:
http://ble.stalliance.no/
http://olesitune.mine.nu/blelogg/?page_id=131
Dual mode chip---iPhone 4s
http://www.macnn.com/articles/11/10/04/lower.power.use.lower.latency/
http://www.eetimes.com/design/communications-design/4218319/Bluetooth-4-0--An-introduction-to-Bluetooth-Low-Energy-Part-II

Friday, October 19, 2012

Prefixing property names with underscore

At first glance on following piece of code,it was sheer frustration on noticing underscore prefixed with the property name.
someClass.h

@interface someClass : NSObject
@property (strong) UIImage* thumbImage;

someClass.m
@implementation someClass

@synthesize thumbImage=_thumbImage;

Reason to prefix underscore is it clearly distinguishes between local variable and instance variable(iVar).And also to avoid compiler warnings( Local declaration of 'thumbImage' hides instance variable) we need to prefix underscore with the property names.

Apple recommends that instance variable can have same name as property names,property names can start with lower case letter,local variables also can start with lower case letter.There comes the problem when you see a piece of code where we can't say whether the variable is an iVar or local variable by this naming convention.To fix all these issues,prefix underscore with the property names.


Tuesday, October 9, 2012

ios

ios consists of 4 layers.
 cocoa Touch
 core Media
 core services
 core OS

Cocoa Touch:
Accelerometer,Multi touch,View hierarchy,image picker,camera,alerts,web view

Core Media:
Core Audio,Audio recording,Open GL,Animations,Quartz

Core Services:
Core Location,Networking,File Access,SQLite,Threading

Core OS:
Sockets,Bonjour,security,Power mgmt,keychain,certificates,File system

Tuesday, October 2, 2012

Rating of app



Prompting a user to provide a rating is straight forward: using the User Defaults system, we’ll record the date of the first launch. When the user crosses an installed-age threshold, we’ll ask for a rating using alert-view and — with their permission — take them right to the app’s page in the Store to enter a rating. To prompt the user for a rating after the app’s been installed for 10 or more days add the following code the viewDidLoad method in its main view controller:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 
if (! [defaults objectForKey:@"firstRun"]) {
 [defaults setObject:[NSDate date] forKey:@"firstRun"];
}
 
NSInteger daysSinceInstall = [[NSDate date] timeIntervalSinceDate:[defaults objectForKey:@"firstRun"]] / 86400;
if (daysSinceInstall > 10 && [defaults boolForKey:@"askedForRating"] == NO) {
 [[[UIAlertView alloc] initWithTitle:@"Like This App?" message:@"Please rate it in the App Store!" delegate:self cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Rate It!", nil] show]; 
 [defaults setBool:YES forKey:@"askedForRating"];
}

[[NSUserDefaults standardUserDefaults] synchronize];


To launch the open the app’s page in the App Store when the user taps the “Rate It!” button subscribe to the UIAlertViewDelegate protocol and implement it’s callback method. Add the protocol to the view controller’s header file, e.g.:
@interface RootViewController : UIViewController <UIAlertViewDelegate> {
 // ...
}


Add the callback method to the view controller’s implementation:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
 if (buttonIndex == 1) {
  NSURL *url = [NSURL URLWithString:@"YOUR URL TBD!!!"];
  [[UIApplication sharedApplication] openURL:url];
 }
}
This callback opens the app's page in the App Store by launching its URL. To determine your's app's URL:
  1. Open iTunes on your Mac
  2. Select iTunes Store from the left-panel
  3. Enter your app's name in the Search iTunes Store text field and hit enter
  4. Control-click on your app's icon and select Copy iTunes Store URL
Opening an App Store URL doesn't work in the simulator; so test this on a device.
To know more: http://mobileorchard.com/fighting-back-against-the-app-stores-negative-rating-bias/