http://www.aviary.com/ios-documentation
My Self Rahul Virja i worked on iphone apps & game developing from Ahmadabad(India).
Thursday, 15 March 2012
Monday, 12 March 2012
how to make lazyTableLoading Images.............
https://developer.apple.com/library/ios/#samplecode/LazyTableImages/Listings/Classes_AppRecord_h.html
Thursday, 8 March 2012
how to send Mail.........
-(void)sendMail{
if ([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSDate *date = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy HH:mm:ss a"];
NSString *strDate = [formatter stringFromDate:date];
[picker setSubject:[NSString stringWithFormat:@"Contact Backup : %@", strDate]];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@""];
[picker setToRecipients:toRecipients];
Support/iPhone Simulator/5.0/Applications/8FFDED4D-0FEF-4E3C-9B43-3677E6B4881D/Documents/contacts.vcf"];
NSURL *theURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"contacts.vcf"];
NSData *myData = [NSData dataWithContentsOfURL:theURL];
// NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"text/vcard" fileName:@"contacts.vcf"];
// Fill out the email body text
NSString *emailBody = @"Here I am sending Contact Backup. \n \nNote: Send this email to yourself and when you lost contact use this email and restore contacts.";
[picker setMessageBody:emailBody isHTML:NO];
picker.mailComposeDelegate=self;
[self presentModalViewController:picker animated:YES];
[picker release];
btnBackup.tag=1;
[btnBackup setImage:[UIImage imageNamed:@"back up.png"] forState:UIControlStateNormal];
[btnBackup removeTarget:self action:@selector(sendMail) forControlEvents:UIControlEventTouchUpInside];
[btnBackup addTarget:self action:@selector(btnBackupClicked:) forControlEvents:UIControlEventTouchUpInside];
progressCount = 0;
progressView.progress=progressCount;
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
lblContact.textAlignment = UITextAlignmentCenter;
lblContact.font = [UIFont boldSystemFontOfSize:18];
lblContact.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
lblContact.text = @"Mail Sending cancelled";
break;
case MFMailComposeResultSaved:
lblContact.text = @"Mail saved";
break;
case MFMailComposeResultSent:
lblContact.text = @"Mail sent successfully";
break;
case MFMailComposeResultFailed:
lblContact.text = @"Sending failed";
break;
default:
lblContact.text = @"Mail not sent";
break;
}
[self dismissModalViewControllerAnimated:YES];
}
if ([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSDate *date = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy HH:mm:ss a"];
NSString *strDate = [formatter stringFromDate:date];
[picker setSubject:[NSString stringWithFormat:@"Contact Backup : %@", strDate]];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@""];
[picker setToRecipients:toRecipients];
Support/iPhone Simulator/5.0/Applications/8FFDED4D-0FEF-4E3C-9B43-3677E6B4881D/Documents/contacts.vcf"];
NSURL *theURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"contacts.vcf"];
NSData *myData = [NSData dataWithContentsOfURL:theURL];
// NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"text/vcard" fileName:@"contacts.vcf"];
// Fill out the email body text
NSString *emailBody = @"Here I am sending Contact Backup. \n \nNote: Send this email to yourself and when you lost contact use this email and restore contacts.";
[picker setMessageBody:emailBody isHTML:NO];
picker.mailComposeDelegate=self;
[self presentModalViewController:picker animated:YES];
[picker release];
btnBackup.tag=1;
[btnBackup setImage:[UIImage imageNamed:@"back up.png"] forState:UIControlStateNormal];
[btnBackup removeTarget:self action:@selector(sendMail) forControlEvents:UIControlEventTouchUpInside];
[btnBackup addTarget:self action:@selector(btnBackupClicked:) forControlEvents:UIControlEventTouchUpInside];
progressCount = 0;
progressView.progress=progressCount;
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
lblContact.textAlignment = UITextAlignmentCenter;
lblContact.font = [UIFont boldSystemFontOfSize:18];
lblContact.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
lblContact.text = @"Mail Sending cancelled";
break;
case MFMailComposeResultSaved:
lblContact.text = @"Mail saved";
break;
case MFMailComposeResultSent:
lblContact.text = @"Mail sent successfully";
break;
case MFMailComposeResultFailed:
lblContact.text = @"Sending failed";
break;
default:
lblContact.text = @"Mail not sent";
break;
}
[self dismissModalViewControllerAnimated:YES];
}
how to fetch facebook contacts,,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
nav = [[UINavigationController alloc] initWithRootViewController:self.viewController];
nav.navigationBar.barStyle = UIBarStyleBlack;
[self.window addSubview:nav.view];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
facebook = [[Facebook alloc] initWithAppId:@"181376618640260" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_likes",
@"read_stream",
@"friends_about_me",
@"user_about_me",
@"user_birthday",
@"friends_birthday",
nil];
[facebook authorize:permissions];
[permissions release];
}
strFBUrl = [NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@&fields=id,name,picture,first_name,birthday",facebook.accessToken];
NSURL *jsonURL = [NSURL URLWithString:strFBUrl];
arrContacts = [[NSMutableArray alloc] initWithArray:[[self getJsonData:jsonURL] objectForKey:@"data"]];
return YES;
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [facebook handleOpenURL:url];
}
-(NSMutableDictionary*)getJsonData :(NSURL *)jsonURL {
NSMutableDictionary *dict = [[[NSMutableDictionary alloc] init] autorelease];
NSError *err;
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL usedEncoding:nil error:&err];
if(jsonData == nil){
//NSLog(@"Data NIL.....");
}
else{
SBJSON *json = [[SBJSON alloc] init];
NSError *error = nil;
dict = [json objectWithString:jsonData error:&error];
[json release];
}
[jsonData release];
return dict;
}
// to disply facebook contacts in tableview
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 80.0;
}
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [appdel.arrContacts count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
// Show disclosure only if this view is related to showing nearby places, thus allowing
// the user to check-in.
}
NSMutableDictionary *dictTemp = [appdel.arrContacts objectAtIndex:indexPath.row];
cell.textLabel.text = [dictTemp objectForKey:@"name"];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 2;
// If extra information available then display this.
cell.detailTextLabel.text = [dictTemp objectForKey:@"birthday"];
cell.detailTextLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0];
cell.detailTextLabel.lineBreakMode = UILineBreakModeCharacterWrap;
cell.detailTextLabel.numberOfLines = 2;
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[dictTemp objectForKey:@"picture"]]]];
cell.imageView.image = image;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Only handle taps if the view is related to showing nearby places that
// the user can check-in to.
}
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
nav = [[UINavigationController alloc] initWithRootViewController:self.viewController];
nav.navigationBar.barStyle = UIBarStyleBlack;
[self.window addSubview:nav.view];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
facebook = [[Facebook alloc] initWithAppId:@"181376618640260" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_likes",
@"read_stream",
@"friends_about_me",
@"user_about_me",
@"user_birthday",
@"friends_birthday",
nil];
[facebook authorize:permissions];
[permissions release];
}
strFBUrl = [NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@&fields=id,name,picture,first_name,birthday",facebook.accessToken];
NSURL *jsonURL = [NSURL URLWithString:strFBUrl];
arrContacts = [[NSMutableArray alloc] initWithArray:[[self getJsonData:jsonURL] objectForKey:@"data"]];
return YES;
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [facebook handleOpenURL:url];
}
-(NSMutableDictionary*)getJsonData :(NSURL *)jsonURL {
NSMutableDictionary *dict = [[[NSMutableDictionary alloc] init] autorelease];
NSError *err;
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL usedEncoding:nil error:&err];
if(jsonData == nil){
//NSLog(@"Data NIL.....");
}
else{
SBJSON *json = [[SBJSON alloc] init];
NSError *error = nil;
dict = [json objectWithString:jsonData error:&error];
[json release];
}
[jsonData release];
return dict;
}
// to disply facebook contacts in tableview
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 80.0;
}
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [appdel.arrContacts count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
// Show disclosure only if this view is related to showing nearby places, thus allowing
// the user to check-in.
}
NSMutableDictionary *dictTemp = [appdel.arrContacts objectAtIndex:indexPath.row];
cell.textLabel.text = [dictTemp objectForKey:@"name"];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 2;
// If extra information available then display this.
cell.detailTextLabel.text = [dictTemp objectForKey:@"birthday"];
cell.detailTextLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0];
cell.detailTextLabel.lineBreakMode = UILineBreakModeCharacterWrap;
cell.detailTextLabel.numberOfLines = 2;
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[dictTemp objectForKey:@"picture"]]]];
cell.imageView.image = image;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Only handle taps if the view is related to showing nearby places that
// the user can check-in to.
}
how to make .Vcf file
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef contacts = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFDataRef vcards = (CFDataRef)ABPersonCreateVCardRepresentationWithPeople(contacts);
NSString *vcardString = [[NSString alloc] initWithData:(NSData *)vcards encoding:NSUTF8StringEncoding];
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *folderPath = [paths objectAtIndex:0];
NSString *filePath = [folderPath stringByAppendingPathComponent:@"contacts.vcf"];
[vcardString writeToFile:filePath atomically:YES encoding:NSStringEncodingConversionAllowLossy error:nil];
NSLog(@"Documents directory: %@",[fileMgr contentsOfDirectoryAtPath: folderPath error:&error]);
CFRelease(addressBook);
CFArrayRef contacts = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFDataRef vcards = (CFDataRef)ABPersonCreateVCardRepresentationWithPeople(contacts);
NSString *vcardString = [[NSString alloc] initWithData:(NSData *)vcards encoding:NSUTF8StringEncoding];
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *folderPath = [paths objectAtIndex:0];
NSString *filePath = [folderPath stringByAppendingPathComponent:@"contacts.vcf"];
[vcardString writeToFile:filePath atomically:YES encoding:NSStringEncodingConversionAllowLossy error:nil];
NSLog(@"Documents directory: %@",[fileMgr contentsOfDirectoryAtPath: folderPath error:&error]);
CFRelease(addressBook);
how to make tableview with custom switch
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (section==0) {
return array.count;
}
else{
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (indexPath.section==0) {
UISwitch *switchObj = [[UISwitch alloc] initWithFrame:CGRectZero];
[switchObj addTarget:self action:@selector(toggleValue:) forControlEvents:(UIControlEventValueChanged | UIControlEventTouchDragInside)];
switchObj.tag=indexPath.row;
//1 for the on
//0 for the off
if ([[appDel.storeValueArray objectAtIndex:indexPath.row] intValue]==0 && [appDel.storeValueArray count]>=1) {
switchObj.on=NO;
}
else if([appDel.storeValueArray count]>=1){
switchObj.on=YES;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryView = switchObj;
cell.textLabel.text = [array objectAtIndex:indexPath.row];
}
else
{
cell.backgroundColor = [UIColor redColor];
cell.textLabel.text = @"Remove Contacts";
cell.textLabel.textColor = [UIColor whiteColor];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section==1) {
contactsView *contact = [[contactsView alloc]initWithNibName:@"contactsView" bundle:nil];
[self.navigationController pushViewController:contact animated:YES];
[contact release];
}
}
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (section==0) {
return array.count;
}
else{
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (indexPath.section==0) {
UISwitch *switchObj = [[UISwitch alloc] initWithFrame:CGRectZero];
[switchObj addTarget:self action:@selector(toggleValue:) forControlEvents:(UIControlEventValueChanged | UIControlEventTouchDragInside)];
switchObj.tag=indexPath.row;
//1 for the on
//0 for the off
if ([[appDel.storeValueArray objectAtIndex:indexPath.row] intValue]==0 && [appDel.storeValueArray count]>=1) {
switchObj.on=NO;
}
else if([appDel.storeValueArray count]>=1){
switchObj.on=YES;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryView = switchObj;
cell.textLabel.text = [array objectAtIndex:indexPath.row];
}
else
{
cell.backgroundColor = [UIColor redColor];
cell.textLabel.text = @"Remove Contacts";
cell.textLabel.textColor = [UIColor whiteColor];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section==1) {
contactsView *contact = [[contactsView alloc]initWithNibName:@"contactsView" bundle:nil];
[self.navigationController pushViewController:contact animated:YES];
[contact release];
}
}
Subscribe to:
Posts (Atom)