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/