| // // main.m // EmailMe // // Created by 张海男 on 2/17/09. // #import #import #import @interface EmailMeViewController : UIViewController NSMutableArray *data; } @end @implementation EmailMeViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { self.title = @"Email me"; self.tabBarItem.image = [UIImage imageNamed:@"about_tabBar.png"]; //let's set up data first: data = [NSMutableArray arrayWithObjects:[NSMutableArray arrayWithObjects:@"front1",@"back1",@"date1",nil], [NSMutableArray arrayWithObjects:@"front2",@"back2",@"date2",nil], [NSMutableArray arrayWithObjects:@"front3",@"back3",@"date3",nil], [NSMutableArray arrayWithObjects:@"front4",@"back4",@"date4",nil], [NSMutableArray arrayWithObjects:@"front5",@"back5",@"date5",nil],nil]; [data retain]; } return self; } - (void) loadView { self.view = [[UIView alloc] init]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(doEmail:)]; } -(IBAction) doEmail: (id) sender{ ABPeoplePickerNavigationController *pplPicker = [[ABPeoplePickerNavigationController alloc]init]; pplPicker.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonEmailProperty]]; pplPicker.addressBook = ABAddressBookCreate(); pplPicker.peoplePickerDelegate = self; [self presentModalViewController:pplPicker animated:YES]; [pplPicker release]; } -(void)sendDataViaEmail:(NSString*)email{ //building email content: NSString *emailContent = @"This%20is%20an%20Email%20from%20ProjectBlah,%0A"; for (int i = 0;i<[data count];i++){ emailContent = [emailContent stringByAppendingString: [[data objectAtIndex:i]objectAtIndex:0]]; emailContent = [emailContent stringByAppendingString: @"%20"]; emailContent = [emailContent stringByAppendingString: [[data objectAtIndex:i]objectAtIndex:1]]; emailContent = [emailContent stringByAppendingString: @"%20"]; emailContent = [emailContent stringByAppendingString: [[data objectAtIndex:i]objectAtIndex:2]]; emailContent = [emailContent stringByAppendingString: @"%20%0A"]; } NSString *urlString = [NSString stringWithFormat: @"mailto:%@?subject=%@&body=%@",email,@"Your%20Card%20from%20ProjectBlah",emailContent]; NSURL *url = [NSURL URLWithString:urlString]; [[UIApplication sharedApplication] openURL:url]; } #pragma mark ABPeoplePickerNavigationControllerDelegate - (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{ [self dismissModalViewControllerAnimated:YES]; } - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{ return YES; } - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{ ABMultiValueRef emails = ABRecordCopyValue(person, property); CFIndex emailIndex = ABMultiValueGetIndexForIdentifier(emails, identifier); CFStringRef email = ABMultiValueCopyValueAtIndex(emails, emailIndex); [self sendDataViaEmail:(NSString*)email]; CFRelease(email); CFRelease(emails); [self dismissModalViewControllerAnimated:YES]; return NO; } - (void)dealloc { [data release]; [super dealloc]; } @end @interface EmailMeAppDelegate : NSObject {} @end @implementation EmailMeAppDelegate - (void)applicationDidFinishLaunching:(UIApplication *)application { UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after app launch EmailMeViewController *viewController = [[EmailMeViewController alloc] initWithNibName:nil bundle:nil]; UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:viewController]; [viewController release]; [window addSubview:nvc.view]; [window makeKeyAndVisible]; } - (void)dealloc { [super dealloc]; } @end int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, @"EmailMeAppDelegate"); [pool release]; return retVal; } |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9059159/viewspace-592074/ ,如需转载,请注明出处,否则将追究法律责任。