Browse Author: surjit.joshi

Get SIM card details of iPhone

Here is the code to get SIM card details of iPhone

1) Add CoreTelephony framework

2) Import following libraries

#import <CoreTelephony/CTCarrier.h>

#import <CoreTelephony/CTTelephonyNetworkInfo.h>

3) Use this code to get details

CTTelephonyNetworkInfo* info = [[CTTelephonyNetworkInfo alloc] init];

CTCarrier* carrier = info.subscriberCellularProvider;

NSString *carrierName = carrier.carrierName;

NSLog(@”carrier : %@”, carrier);

// Here are some parameters

//NSString *mobileCountryCode = carrier.mobileCountryCode;

//NSString *isoCountryCode = carrier.isoCountryCode;

//NSString *mobileNetworkCode = carrier.mobileNetworkCode;




Can we create flashing red/blue circle around user location in mapview in iPhone ?

Yes we can create with a simple UIView animation & few images.

1) Add the MapView

MKMapView *mapView = [[MKMapView alloc] initWithFrame:yourFrameFrame];

mapView.mapType = MKMapTypeStandard;

mapView.delegate = self;

[mapView setShowsUserLocation:YES];

[self.view addSubview:mapView];


2) In viewForAnnotation method
– (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation: (id <MKAnnotation>)annotation


UIImage *anImage = nil;

UIImageView *overlayImage;

if (annotation == mapview.userLocation)


MKPinAnnotationView *customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@”annotation”] autorelease];

customPinView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@”redLocation.png” ofType:nil]];

customPinView.animatesDrop = NO;

customPinView.canShowCallout = YES;


overlayImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”OverlayImage.png”]];

overlayImage.frame = CGRectMake(0, 0, 15, 15); = CGPointMake(,;

[customPinView addSubview:overlayImage];

// timer for animation

NSTimer *mapTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(createOverlayAnimation) userInfo:nil repeats:YES];



return customPinView;





overlayImage.transform = CGAffineTransformMakeScale(1,1);

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:1.0];

overlayImage.transform = CGAffineTransformMakeScale(5,5);

overlayImage.alpha = 1.0;

[UIView commitAnimations];


Using FBGraph in iPhone

The FBGraph API is bit complex, but much useful than any other ways for accessing contents of Facebook.



Object Output:


“name”: “Facebook Platform”,

“type”: “page”,

“website”: “”,

“username”: “platform”,

“founded”: “May 2007”,

“company_overview”: “Facebook Platform enables anyone to build…”,

“mission”: “To make the web more open and social.”,

“products”: “Facebook Application Programming Interface (API)…”,

“fan_count”: 449921,

“id”: 19292868552,

“category”: “Technology”



All objects in Facebook can be accessed in the same way:


* Users: (Bret Taylor)

* Pages: (Coca-Cola page)

* Events: (Facebook Developer Garage


* Groups: (Emacs users group)

* Applications: (the Graffiti app)

* Status messages: (A status message

from Bret)

* Photos: (A photo from the Coca-Cola


* Photo albums: (Coca-Cola’s wall


* Videos: (A Facebook tech talk on


* Notes: (Note announcing Facebook

for iPhone 3.0)


Logged-in User Objects


* Friends:

* News feed:

* Profile feed (Wall):

* Likes:

* Movies:

* Books:

* Notes:

* Photos:

* Videos:

* Events:

* Groups:




fields =>,name,picture

ids =>,vernal

current user =>






“name”: “Facebook Developer Garage Austin – SXSW Edition”,

“metadata”: {

“connections”: {

“feed”: “”,

“picture”: “”,

“invited”: “”,

“attending”: “”,

“maybe”: “”,

“noreply”: “”,

“declined”: “”








The steps to obtain an access token are:


* Get App ID and secret.


* Redirect the user to with your

client_id and the callback URL:




* Redirect the user back to the callback URL you specified with a verification

string in the argument code, which can be exchanged for an oauth access token.






* Use the access token returned by the request above to make requests on behalf

of the user:…




curl -F ‘access_token=…’

-F ‘body=Hello, Arjun. I like this new API.’


curl -F ‘access_token=…’



We support writing the following types of objects:


Method               Description                           Arguments



/PROFILE_ID/feed     write to the given profile’s feed/wall message,

picture, link, name, description

/POST_ID/comments   comment on the given post             message

/POST_ID/likes       like the given post                   none

/PROFILE_ID/notes   write a note on the given profile     message, subject

/PROFILE_ID/links   write a link on the given profile     link, message

/EVENT_ID/attending attend the given event                 none

/EVENT_ID/maybe     maybe attend the given event           none

/EVENT_ID/declined   decline the given event               none


curl -F ‘access_token=…’

-F ‘message=I am posting to my own feed. I am awesome.’








<img src=””/>


* People:

* Events:

* Groups:

* Pages:

* Applications:

* Photo Albums:



– square (50×50)

– small  (50 pixels wide, variable height)

– large (about 200 pixels wide, variable height)





* limit, offset:

* until, since (a unix timestamp or any date accepted by strtotime):





* All public posts:

* People:

* Pages:

* Events:

* Groups:


News Feed:





Obtain Access Token:


curl -F type=client_cred

-F client_id=your_app_id

-F client_secret=your_app_secret……



* since

* until…&since=yesterday


Now, Passing these parameters to FBGraph in iPhone way.

1) Get Authentication (get access_token) :

/*Facebook Application ID*/

NSString *client_id = @“your app id”;

//alloc and initalize our FbGraph instance

self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];

// //begin the authentication process…..

[fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallbackForRegister:)
andExtendedPermissions:@”user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins,email,user_birthday,user_online_presence” andSuperView:self.view] ;

**Note : fbGraphCallbackForRegister method returns access_token.


2) Logged-In UserInfo :

FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@”me” withGetVars:nil];

NSLog(@”getMeButtonPressed:  %@”, fb_graph_response.htmlResponse);

3) Get Logged-In user profile picture :
There are few sizes of profile picture.


4) Get User Friends (Needs authentication)

FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@”me/friends” withGetVars:nil];

NSLog(@”getFriendsButtonPressed:  %@”, fb_graph_response.htmlResponse);




Draw a line by touch On UIImageView in iPhone

Its much useful for drawing something on screen by touch.

1) Declare 4 objects in .h file

CGPoint lastPoint;

BOOL mouseSwiped;

int mouseMoved;

UIImageView *signImage;
2) First create a UIImageView object ie. a blank image in viewDidLoad

signImage = [[UIImageView alloc ] initWithFrame:CGRectMake(15, 60, 290, 320)];

signImage.image = nil;

signImage.tag = 1000;

signImage.layer.borderWidth = 3.0;

signImage.layer.borderColor = [[UIColor lightGrayColor] CGColor];

[self.view addSubview:signImage];


2) Then add 3 methods TouchesBegin, TouchesMoved & TouchesEnd

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event


mouseSwiped = NO;

UITouch *touch = [touches anyObject];

CGPoint touchLocation = [touch locationInView:self.view];


if (CGRectContainsPoint(signImage.frame, touchLocation))


lastPoint = [touch locationInView:signImage];



NSLog(@”Last :%.2f – %.2f”,lastPoint.x, lastPoint.y);



– (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

mouseSwiped = YES;

CGPoint currentPoint;

UITouch *touch = [touches anyObject];

CGPoint touchLocation = [touch locationInView:self.view];


if (CGRectContainsPoint(signImage.frame, touchLocation))


currentPoint = [touch locationInView:signImage];


[first_signImage.image drawInRect:CGRectMake(0, 0, signImage.frame.size.width, signImage.frame.size.height)];

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);

CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);


CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);

CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);


signImage.image = UIGraphicsGetImageFromCurrentImageContext();




//currentPoint.y -= 150;


lastPoint = currentPoint;




if (mouseMoved == 10) {

mouseMoved = 0;





– (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event


if(!mouseSwiped) {


CGPoint currentPoint;

UITouch *touch = [touches anyObject];

CGPoint touchLocation = [touch locationInView:self.view];


if (CGRectContainsPoint(signImage.frame, touchLocation))


currentPoint = [touch locationInView:signImage];



[signImage.image drawInRect:CGRectMake(0, 0, signImage.frame.size.width, signImage.frame.size.height)];

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);

CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);


CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);

CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);


signImage.image = UIGraphicsGetImageFromCurrentImageContext();







Simple Custom UITabBarController with UINavigationController in iPhone/iPad programatically

//In AppDelegate.h file

UITabBarController *tabBarController;

@property (strong, nonatomic) UITabBarController *tabBarController;


//In AppDelegate.h.m file

@synthesize tabBarController = _tabBarController;



self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];


NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] init];


self.tabBarController = [[[UITabBarController alloc] init] autorelease];


UIViewController *viewController1 = [[[ViewController1 alloc] initWithNibName:@“ViewController1″ bundle:nil] autorelease];

UIViewController *viewController2 = [[[ViewController2 alloc] initWithNibName:@”ViewController2″ bundle:nil] autorelease];

UIViewController *viewController3 = [[[ViewController3 alloc] initWithNibName:@”ViewController3″ bundle:nil] autorelease];

UIViewController *viewController4 = [[[ViewController4 alloc] initWithNibName:@”ViewController4″ bundle:nil] autorelease];

UIViewController *viewController5 = [[[ViewController5 alloc] initWithNibName:@”ViewController5″ bundle:nil] autorelease];


UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];

UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];

UINavigationController *navigationController3 = [[UINavigationController alloc] initWithRootViewController:viewController3];

UINavigationController *navigationController4 = [[UINavigationController alloc] initWithRootViewController:viewController4];

UINavigationController *navigationController5 = [[UINavigationController alloc] initWithRootViewController:viewController5];


navigationController1.navigationBar.barStyle = UIBarStyleDefault;

navigationController2.navigationBar.barStyle = UIBarStyleDefault;

navigationController3.navigationBar.barStyle = UIBarStyleDefault;

navigationController4.navigationBar.barStyle = UIBarStyleDefault;

navigationController5.navigationBar.barStyle = UIBarStyleDefault;


navigationController1.navigationBar.tintColor = [UIColor whiteColor];

navigationController2.navigationBar.tintColor = [UIColor blackColor];

navigationController3.navigationBar.tintColor = [UIColor blackColor];

navigationController4.navigationBar.tintColor = [UIColor blackColor];

navigationController5.navigationBar.tintColor = [UIColor blackColor];


navigationController4.navigationItem.hidesBackButton = YES;


//viewController1.title = @”ViewController1″;

viewController2.title = @”ViewController2″;

viewController3.title = @”ViewController3″;

viewController4.title = @”ViewController4″;

viewController5.title = @”ViewController5″;


[tabBarViewControllers addObject:navigationController1];

[tabBarViewControllers addObject:navigationController2];

[tabBarViewControllers addObject:navigationController3];

[tabBarViewControllers addObject:navigationController4];

[tabBarViewControllers addObject:navigationController5];


self.tabBarController.viewControllers = tabBarViewControllers;


self.window.rootViewController = self.tabBarController;


[self.window makeKeyAndVisible];


Play YouTube video using UIWebView on iPhone


Sometimes it gets very difficult to find a way to do simple things. Playing videos on iPhone is a simple thing, using UIWebView. Just need to embed the URL to HTML tags, and then load the HTML in UIWebView.

Here is the code to do so.

Pass you URL of YouTube Video in “urlStr”.

//In .h file
UIWebView *videoView;
// In .m file

videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 385)];

[self embedYouTube :urlStr  frame:CGRectMake(0, 0, 320, 385)];

[self.view addSubview:videoView];

// methos to embed URL in HTML & load it to UIWebView

– (void)embedYouTube:(NSString*)url frame:(CGRect)frame


NSString* embedHTML = @”


<style type=”text/css”>

body {

background-color: transparent;

color: white;



</head><body style=”margin:0″>

<embed id=”yt” src=”%@” type=”application/x-shockwave-flash”

width=”%0.0f” height=”%0.0f”></embed>



NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];

if(videoView == nil) {

videoView = [[UIWebView alloc] initWithFrame:frame];

[self.view addSubview:videoView];


[videoView loadHTMLString:html baseURL:nil];


**Note : The UIWebView for YouTube video doesn’t load when you run it on Simulator, work on device perfectly.


Five ways to pull yourself out of workaholism

‘In sickness and in health and till death do us part’ – if these are the vows your family and friends think you have exchanged with your Blackberry/keyboard/iPad, then you are a certified workaholic.

The symptoms are many, but some of the significant ones are that you punch away nonstop, receive every call from office and take your meals at odd hours to finish that extra bit at work.

All this leads to anxiety disorders, repetitive stress injury, mental and physical fatigue, and this strong alliance with work is best severed at the start. ET suggests how you can do that.


Draw Clear Boundaries

Clocking out of work is just as important as clocking in. Working post-office hours is acceptable if there is an urgent assignment but if it becomes a habit, alarm bells should start ringing. It helps to unplug phones and computers during vacations and non-working hours.

Check on Employees

Employers need to look into the employees’ attendance sheets and office hours. Sabre, for instance, found that despite giving employees access to wellness centres, counselling sessions and discount coupons at gyms, they were still packing in extra hours at work. The firm, therefore, does not offer the option of carrying forward holidays .

Say a Firm ‘No’

‘Workaholics anonymous’ groups don’t exist, but instead, a simple ‘no’ can go a long way. Complete your tasks first, and only if there is time to spare, offer another a helping hand. Once the tasks are done, wait for the next day to start on the new list of chores.

Extra isn’t Always Healthy

The boss often thinks that those who work round the clock are the productive ones. But a smart worker can be someone who punches in the required hours, completes his work and leaves office on time too.

In a recent Randstad survey of state-owned companies, 80% of employees said they received work-related calls and emails beyond office hours. Nearly 69% said they volunteered to work post-office hours while 79% received work-related calls and emails on holidays. Long hours lead to a dip in productivity and creativity.

Watch your Schedule

Often, the employee in the cubicle next to you could be a night owl at the office, but that need not be your style. Excessive breaks, long water-cooler conversations will ultimately lead to more time in the office, and not a very fruitful schedule.

So what’s the moral of the story??
* Very clear, LEAVE ON TIME!!!
* Never put in extra time ‘ unless really needed ‘
* Don’t stay back unnecessarily and spoil your company work culture which will in turn cause inconvenience to you and your colleagues.

How to create iPhone/iPad’s “Slide to Unlock” animation ?

This is how Apple implemented “Slider to Unlock” or “Slide to Power off” animation.

In .h file

UISlider *slider;

BOOL touchIsDown;

CALayer *textLayer;



– (void)viewDidLoad


self.view.layer.backgroundColor = [[UIColor grayColor] CGColor];

UIImageView *sliderBackView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”SliderBack1.png”]];

sliderBackView.frame = CGRectMake(20, 20, 260, 50);

sliderBackView.userInteractionEnabled = YES;

[self.view addSubview:sliderBackView];


slider = [[UISlider alloc] initWithFrame:CGRectMake(5, 12, 250, 27)];

[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];

[slider addTarget:self action:@selector(sliderUp:) forControlEvents:UIControlEventTouchUpInside];

[slider addTarget:self action:@selector(sliderDown:) forControlEvents:UIControlEventTouchDown];

slider.minimumValue = 0;

slider.maximumValue = 100;

slider.value = 0;

slider.continuous = YES;

slider.backgroundColor = [UIColor clearColor];

[slider setMinimumTrackImage:[UIImage imageNamed: @”transSlider.png”] forState:UIControlStateNormal];

[slider setMaximumTrackImage:[UIImage imageNamed: @”transSlider.png”] forState:UIControlStateNormal];

[slider setThumbImage:[UIImage imageNamed:@”SliderThumb.png”] forState:UIControlStateNormal];

[sliderBackView addSubview:slider];


NSString *labelText = @”Slide to Unlock”;

UIFont *labelFont = [UIFont systemFontOfSize:18];

CGSize labelSize = [labelText sizeWithFont:labelFont];


UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 0.0, labelSize.width, labelSize.height)];

label.textColor = [UIColor whiteColor];

label.textAlignment = UITextAlignmentCenter;

label.backgroundColor = [UIColor clearColor];

label.font = labelFont;

label.text = labelText;



[label.layer renderInContext:UIGraphicsGetCurrentContext()];

CGImageRef viewImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage];



UIImage *textImage = [UIImage imageWithCGImage:viewImage];


CGFloat textWidth = textImage.size.width;

CGFloat textHeight = textImage.size.height;


textLayer = [CALayer layer];

textLayer.contents = (id)[textImage CGImage];

textLayer.frame = CGRectMake(78.0f, 15.0f, textWidth, textHeight);  //set frame here


CALayer *maskLayer = [CALayer layer];


// Mask image ends with 0.15 opacity on both sides. Set the background color of the layer

// to the same value so the layer can extend the mask image.

maskLayer.backgroundColor = [[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.15f] CGColor];

maskLayer.contents = (id)[[UIImage imageNamed:@”Mask.png”] CGImage];


// Center the mask image on twice the width of the text layer, so it starts to the left

// of the text layer and moves to its right when we translate it by width.

maskLayer.contentsGravity = kCAGravityCenter;

maskLayer.frame = CGRectMake(-textWidth, 0.0f, textWidth * 2, textHeight);


// Animate the mask layer’s horizontal position

CABasicAnimation *maskAnim = [CABasicAnimation animationWithKeyPath:@”position.x”];

maskAnim.byValue = [NSNumber numberWithFloat:textWidth];

maskAnim.repeatCount = 1e100f;

maskAnim.duration = 1.5f;

[maskLayer addAnimation:maskAnim forKey:@”slideAnim”];


textLayer.mask = maskLayer;

[sliderBackView.layer addSublayer:textLayer];



[super viewDidLoad];



– (IBAction) sliderAction : (id) sender


NSLog(@”%f”, slider.value);

textLayer.opacity = MAX(0.0, 1.0 – (slider.value * 3.5));


if(slider.value >= 45)


//slider.value = slider.maximumValue;


[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:0.3];

slider.value = slider.maximumValue;

[UIView commitAnimations];


textLayer.opacity = MAX(0.0, 1.0 – (slider.value * 3.5));





if(slider.value >= 5)


textLayer.opacity = textLayer.opacity-0.05;






– (void) sliderUp: (UISlider *) sender


if (touchIsDown)


touchIsDown = NO;


if(slider.value < 45)


[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:0.3];

slider.value = slider.minimumValue;

[UIView commitAnimations];


textLayer.opacity = 1.0;





– (void) sliderDown: (UISlider *) sender


touchIsDown = YES;



This is complete code for Lazy People..

How to Create UILocalNotification, repeating every minute ?

There are two types of notifications in iOS, One is Local notification & other is PUsh notification. Added code to create Local notification.

// creating notification
NSDate *newDate = [NSDate dateWithTimeIntervalSinceNow:60];

// where 60 = seconds, so add your seconds here
Class cls = NSClassFromString(@”UILocalNotification”);
if (cls != nil) {
UILocalNotification *notification = [[cls alloc] init];
notification.fireDate = newDate;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = @“My Notification”;
notification.alertAction = @”Show me”;
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 1;
notification.repeatInterval = NSMinuteCalendarUnit;
NSString *str = @“String to pass”;
NSDictionary *userDict = [NSDictionary dictionaryWithObject:str forKey:@“myNotification”];
notification.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release];

// receiving notification
– (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
NSLog(@”Notification: %@”, [notification.userInfo objectForKey:@“myNotification”]);

Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box