Upload
eakapong-kattiya
View
1.111
Download
4
Embed Size (px)
DESCRIPTION
iOS Development Basic Debugging & Performance by Eakapong Kattiya [email protected] www.ibluecode.com +66 086-673-2111
Citation preview
iOS Basic Development
User Selection Design
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Social Share
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
UIActionSheet
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
- (IBAction)shareSocial:(id)sender { UIActionSheet *action = [[UIActionSheet alloc]initWithTitle:@"Social Network" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Facebook",@"Twitter", @"Instagram",@"Email", nil]; [action showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ if(buttonIndex == 0){ [self directShareFacebook:nil]; } if(buttonIndex == 1){ [self directShareTwitter:nil]; } if(buttonIndex == 2){ [self directShareInstagram:nil]; } if(buttonIndex == 3){ [self directSendMail:nil]; }}
UIActionSheet
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Social Framework
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
- (IBAction)directShareFacebook:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; [composeVC setInitialText:self.myTextView.text]; UIImage *image = self.myImageView.image; [composeVC addImage:image]; NSURL *url = [NSURL URLWithString:@"http://www.ibluecode.com"]; [composeVC addURL:url]; [self presentViewController:composeVC animated:YES completion:nil]; }}
SLComposeViewController : Facebook
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Social Framework
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
- (IBAction)directShareTwitter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; [composeVC setInitialText:self.myTextView.text]; UIImage *image = self.myImageView.image; [composeVC addImage:image]; NSURL *url = [NSURL URLWithString:@"http://www.ibluecode.com"]; [composeVC addURL:url]; [self presentViewController:composeVC animated:YES completion:nil]; }}
SLComposeViewController : Twitter
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
UIDocumentInteractionController
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
- (IBAction)openDocumentAction:(id)sender {
NSURL *url = [[NSBundle mainBundle] URLForResource:@"mac_pro" withExtension:@"jpg"]; self.docController = [UIDocumentInteractionController interactionControllerWithURL:url]; self.docController.delegate = self ; BOOL isValid = [[UIApplication sharedApplication] canOpenURL:url]; NSLog(@"uti: %@", [self.docController UTI]); if(isValid){ [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES]; }
}
UIDocumentInteractionController : All
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
- (IBAction)directShareInstagram:(id)sender { NSURL *instagramURL = [NSURL URLWithString:@"instagram://location?id=1"]; if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) { NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"Image.igo"]; NSData *imageData = UIImagePNGRepresentation(self.myImageView.image); [imageData writeToFile:savedImagePath atomically:YES]; NSURL *imageUrl = [NSURL fileURLWithPath:savedImagePath]; NSLog(@"%@",imageUrl); UIDocumentInteractionController *docController = [UIDocumentInteractionController new]; docController.delegate = self; docController.UTI = @"com.instagram.exclusivegram"; docController.URL = imageUrl; [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}else{
[self showAlertView:@"Please install Instagram before share."]; }
}
UIDocumentInteractionController : Instagram
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
UIAlertView
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
-(void)showAlertView:(NSString*)title{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show];}
UIAlertView
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
MFMailComposeViewController
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
- (IBAction)directSendMail:(id)sender {
if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init]; mailVC.mailComposeDelegate = self; [mailVC setSubject:@"Subject"]; NSArray *toRecipients = [NSArray arrayWithObjects: @"[email protected]", @"[email protected]", nil];
[mailVC setToRecipients:toRecipients]; UIImage *myImage = self.myImageView.image ; NSData *imageData = UIImagePNGRepresentation(myImage); [mailVC addAttachmentData:imageData mimeType:@"image/png" fileName:@"attachment"]; NSString *emailBody = self.myTextView.text; [mailVC setMessageBody:emailBody isHTML:NO]; //iOS 5 //[self presentModalViewController:mailer animated:YES]; //iOS 6 [self presentViewController:mailVC animated:YES completion:nil]; }}
MFMailComposeViewController
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
UIPickerView
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Class : UIPickerView
Framework : UIKit
Sample Code : UICatalog
Init : initWithFrame : (CGRect) or Interface Builder
Datasource : – numberOfComponentsInPickerView: – pickerView:numberOfRowsInComponent:
Delegate : – pickerView:titleForRow:forComponent: – pickerView:viewForRow:forComponent:reusingView: – pickerView:didSelectRow:inComponent:
UIPickerView
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
การเรยกใชงาน
1. Init UIPickerView2. bind Datasouce / Delegate3. กาหนดคอลมน numberOfComponentsInPickerView4. กาหนดจานวนแถว pickerView:numberOfRowsInComponent:5. กาหนดการแสดงคาเปน Text หรอ View ได pickerView:titleForRow:forComponent:
pickerView:viewForRow:forComponent:reusingView:6. ใช Delegate เมอเลอกขอมลเสรจ pickerView:didSelectRow:inComponent
UIPickerView
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
1. Init UIPickerView (.h)
IBOutlet UIPickerView *myPV ;
2. bind Datasouce / Delegate (.m)
[myPV setDataSource:self]; [myPV setDelegate:self]; [myPV selectRow:0 inComponent:0 animated:NO]; [myPV selectRow:0 inComponent:1 animated:NO]; [myPV selectRow:0 inComponent:2 animated:NO];
UIPickerView
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
3. กาหนดคอลมน (.m)
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;{ return 3 ;}
4. กาหนดจานวนแถว (.m)
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;{ if(component == 1){
return 20 ;}if(component == 0){return 30 ;}
return 10 ;}
UIPickerView
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
5. กาหนดการแสดงคาเปน Text หรอ View ได (.m)
#pragma แสดงคาเปน Text
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;{ NSMutableArray *arrayNo1 = [[NSMutableArray alloc] init]; [arrayNo1 addObject:@"0"]; [arrayNo1 addObject:@"1"]; [arrayNo1 addObject:@"2"]; [arrayNo1 addObject:@"3"]; [arrayNo1 addObject:@"4"]; [arrayNo1 addObject:@"5"]; [arrayNo1 addObject:@"6"]; [arrayNo1 addObject:@"7"]; [arrayNo1 addObject:@"8"]; [arrayNo1 addObject:@"9"];
return [arrayNo1 objectAtIndex:row];}
UIPickerView
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
5. กาหนดการแสดงคาเปน Text หรอ View ได (.m)
#pragma แสดงคาเปนรปภาพ
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
NSString *imageName = [NSString stringWithFormat:@"%d.png",row];
UIImageView *bgImageView = [[UIImageView alloc]initWithImage: [UIImage imageNamed:imageName]];
[bgImageView setFrame:CGRectMake(0, 0, 50, 50)];
[bgImageView setContentMode:UIViewContentModeScaleAspectFit];
return bgImageView;
}
UIPickerView
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
6. ใช Delegate เมอเลอกขอมลเสรจ
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ if(component == 0){ inputCol1 = [arrayNo1 objectAtIndex:row]; } else if(component == 1){ inputCol2 = [arrayNo2 objectAtIndex:row]; } else if(component == 2){ inputCol3 = [arrayNo3 objectAtIndex:row]; }
}
UIPickerView
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111
Top Secret
Saturday, June 15, 13
Workshop : Top Secret
Task : สรางหนาจอ Login Password โดย User ตองทาการเลอก Password =246 จาก UIPickerView จากนนจงเขาสหนาจอตอไป สามารถ Reset คาไดจากปม RESET BUTTON
Objective : นกเรยนมความเขาใจในเรอง UIViewController User Interface และ IBOutlet Action-Target Datasouce Delegate
UIPickerView
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
iOS Basic Development
Submit App Store
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Course Outline
1. Introduction & Xcode
2. Objective-C & Frameworks
3. View & ViewController
4. View & ViewController (2)
5. Submit App Store
Course Outline
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Developing iOS Apps : App Store
Add New Application ( iTunes Connect )
Upload required icon and screenshots
Upload Application Binary ( IPA File )
Waiting for app review by apple ( 7 days - Few months)
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
หลงจากทนกเรยนไดเรยนรการพนฐานการเขยนโปรแกรมบน iPhone และการใช Tool ตาง ๆ ไปเรยบรอยแลว
นกเรยนกทาการเขยนโปรแกรมไดอยางราบรน ระหวางทเขยน Code นนกไมม Error อะไร สามารถ Compile และ Run Application ไดโดยไมมการ Crash ของโปรแกรมและการทางานตาง ๆ นนรวดเรวถกตองตามทออกแบบไวทกประการ.....
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
หลงจากทนกเรยนไดเรยนรการพนฐานการเขยนโปรแกรมบน iPhone และการใช Tool ตาง ๆ ไปเรยบรอยแลว
นกเรยนกทาการเขยนโปรแกรมไดอยางราบรน ระหวางทเขยน Code นนกไมม Error อะไร สามารถ Compile และ Run Application ไดโดยไมมการ Crash ของโปรแกรมและการทางานตาง ๆ นนรวดเรวถกตองตามทออกแบบไวทกประการ.....
ใชหรอไม ?
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
โดยปกตแลวขนตอนการเขยนโปรแกรม ระหวางท ทาการ Build & Run จะเปนเชนน
1. Error ! (ไมสามารถ ทาการ Build ได)2. Warning ! (ไม Error แตมการเตอน)3. Crash ! (Build ไดแต Run ไมได)4. Wrong ! (Run ไดแตทางานผด)5. Slow ! (ทางานถกแตชา ไมลน)6. Work ! (ทางานไดถกและเรว)
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
เนองจากเราไมสามารถเขยนโปรแกรมเพยงครงเดยวใหทางานไดถกตองสมบรณได ดงนนจงตองมวธการตรวจสอบการทางานของโปรแกรมไปทละขน ซงเราเรยกวาการ
Debugging
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Debugging
คอโหมดการ Run Application ไปทละขนเพอดทางานของ Application ในจดทเราสนใจวาทางานไดถกตองตามทเราตองการหรอไม โดยขนตอนดงน
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Debugging
- เพม-ลบ breakpoints เพอหยดโปรแกรมในจดทเราสนใจ
- ดคาในตวแปรตาง ๆ ไดโดยการเอา Mouse ไปช
- Run แบบ Step in ,Step Out เพอตรวจสอบขนตอนการทางานของโปรแกรม
- NSLog เพอแสดงขอมลตาง ๆ บนหนาตาง Console
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Understanding Errors
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Understanding Errors
บทนจะอธบายความหมายของ Error ตาง ๆ ทมกเจอบอยซงจะชวยใหเราแกปญหาไดรวดเรวขน และสามารถทาการ Build โปรแกรมได
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Understanding Errors
Expected ‘;’ before ...
สาเหต : - ลมใส ; ปดประโยค
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Understanding Errors
‘Something’ Undeclared
ไมสามารถหาทมาของ Class Something ทเราเรยกใชได
สาเหต : - เขยนชอ Class ผด เชน ตวเลก–ใหญ - ไมได import file หรอ import file ผด - ไมไดทาการ import Framework , library
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Understanding Errors
Statically allocated instance of Objective-C class สาเหต : - ลมใส * ใหกบ Object ทเปนประเภท Dynamic
เชน NSString myString ; ทถกคอ NSString *myString ;
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Understanding Crash Problem
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Understanding Crash Problem
หลงจากทเราแก Error และสามารถ Run โปรแกรมไดแลวจะพบวาโปรแกรมเกดการ Crash ในระหวางททางาน โดยบทนจะอธบายการเกด Crash ทมกเจอไดบอย
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Understanding Crash Problem
“EXC_BAD_ACCESS” สาเหต : - ทาการเรยก Object ทถก release ไปแลว
เชน NSString *myString ;
[myString release] ; // ไมม object แลวmyString = @”Test” ;
การแกไข : - Debug ทละขน หรอ ใชเครองมอ Instruments ตรวจหา Zombies Object
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Understanding Crash Problem
“SIGABRT” = SIGNAL ABORT
เปนคาสงใหหยดการทางานของโปรแกรมเนองจากพบ Error สาเหต : - ทาการเรยก Method ทไมมอย หรอ เรยกผด เชน NSString *myString ;
myString = @”Test” ;[myString releasee] ; // Method releasee นนไมมใน Class
การแกไข : - Debug ทละขน และตรวจสอบ Warning
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Understanding Interface Builder Error
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Understanding Interface Builder Error:
บางครงการ Crash โปรแกรมเกดจากการทเราแกไข file XIB ใน Interface Builder ไดเชนกน สาเหต : - กาหนด Class ผดประเภท
วธแกไข :
- เปดหนาตาง Console แลวดบรรทดลาสดจะบอกรายละเอยดของ Class ท Error อยแลวทาการแกไขใหถกตอง
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Workshop
ใหนกเรยนทา Project ของตวเองแลวทดลอง Debug และแกไข Error ตาง ๆ ทเกดขน
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Performance Tool
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Performance Tool
- Clang Analyzer
- Instruments
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Clang Analyzer
เปนเครองมอในการวเคราะห Code ของเรากอนทาการ Run วาเขยนไดมประสทธภาพหรอไม เชน
- ตรวจสอบจดทนาจะเกด Memory Leaked ได
- ตรวจสอบตวแปรทไมถกเรยกใช
- เรยกใชไดจาก menu Build and Analyze
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Instruments
เปนเครองมอในการทดสอบ Performance ขณะท Run โปรแกรม
- ตรวจสอบจดทเกด Memory Leaked
- ตรวจสอบการจองหนวยความจา
- ตรวจสอบ Zombie Object (Object ทตายหรอถก Release ไปแลวแตมการเรยกใชอก เปรยบเสมอน Zombie ทตายแลวถกเรยกปลกขนมาใหม)
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Workshop
ใหนกเรยนทาการ Test Performance Project ของตวเองดวยเครองมอ Analyzer และ Instruments
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Submit AppStore
- เปดตววนท 10 July 2008- เปนครงแรกและเปนชองทางทงายทสดทจะทาใหนกพฒนาสามารถขาย Application ใหกบคน 155 ประเทศทวโลก- ผใช 400 ลานคนทมบตร Credit
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Submit AppStore
5-March-2012 - จานวน App รวม (iPhone/iPad/iPod Touch) คอ 550,000+- จานวน App บน iPad คอ 170,000 +- ยอด AppStore Download 25,000 ลานครง
12-June-2012- ปจจบนจานวน App รวม (iPhone/iPad/iPod Touch) คอ 650,000+- จานวน App บน iPad คอ 225,000 +- ยอด AppStore Download 30,000 ลานครง
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
Submit AppStore
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
In-App Purchases (Freemium Model)
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
In-App Purchases (Tiny Tower)
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
In-App Purchases
Order and Chaos NBA Jam
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
In-App Purchases (The Smurfs Village)
8-Year-Old Girl Racks Up $1400 Bill Buying Smurfberries in Smurf's Village
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
In-App Purchases (Restrictions)
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13
by Eakapong Kattiya www.ibluecode.com [email protected] +66 086-673-2111Saturday, June 15, 13