COPYRIGHTED MATERIAL. part I Developing a Professional UI. Chapter 1: Creating a Personal Library. Chapter 2: Advancing with Tableviews

Size: px
Start display at page:

Download "COPYRIGHTED MATERIAL. part I Developing a Professional UI. Chapter 1: Creating a Personal Library. Chapter 2: Advancing with Tableviews"

Transcription

1 part I Developing a Professional UI Chapter 1: Creating a Personal Library Chapter 2: Advancing with Tableviews Chapter 3: Advancing with Map Kit Chapter 4: Understanding Action Views and Alerts Chapter 5: Internationalization: Building Apps for the World Chapter 6: Using Multimedia COPYRIGHTED MATERIAL

2

3 1Creating a Personal Library What S IN THIS ChaPter? Creating registering and login logic Configuring application settings Storing settings and securing password Handling crashes in your application Wrox.com Code DoWNloads for this Chapter The wrox.com code downloads for this chapter are found at on the Download Code tab. The code is in the Chapter 1 download and individually named according to the names throughout the chapter. In this chapter you learn how to develop a Personal Library, which is a series of classes and techniques you can use to give you a head start on your projects. Creating a Personal Library will save you time during future projects. The Personal Library you will create during this chapter will teach you how to implement the logic for user registration, user login, and securing password storage. If you ve developed software before, you ve likely noticed a lot of repetitive tasks in each application you ve worked on. This is no different when developing applications for ios, and for that reason Xcode, the Apple Developer Platform, comes with different so-called project templates. The problem with these project templates is that they provide you only with some main object containers and don t provide out-of-the-box configurable features that you require in each application. In this chapter you develop your own configurable Personal Library that you can use for all your subsequent applications. Throughout the different chapters in this book, you extend the Personal Library with additional functionalities.

4 4 CHAPter 1 Creating a Personal Library Creating Your Personal Library The Personal Library you are about to create is basically a project skeleton containing different classes and functionalities to implement repetitive tasks in a flexible and organized way. Functionalities in the Personal Library are: Managing configuration settings Creating a user registration process with a UIViewController Implementing a user login process with a UIViewController Storing user values and secured password storage in a Keychain In your future development projects, you can just drag and drop the files of the Personal Library you require. Understanding Project Basics When you develop ios applications, you have to make some basic choices when you create a new project. Two important choices are: Whether to use Automatic Reference Counting (ARC) Whether to use Interface Builder for the UI composition, or to code the UI components in your controller classes Automatic Reference Counting ARC is a technology introduced in ios 5.x and higher that automatically manages your memory allocations. As the name suggests, it counts the references to objects and retains or releases objects automatically when required. The main advantages of using ARC are: No need to send release or autorelease messages to your objects Less chance for memory leaks in case you forget to release objects Less code to write because you can skip the release for your objects and also skip the dealloc method in most cases The only reason for keeping a dealloc method around is when you need to free resources that don t fall under the ARC umbrella, such as: Calling CFRelease on Core Foundation objects Calling free() on memory you allocated with malloc() Invalidating a timer When you are using source code and/or libraries from other parties, you must keep in mind that not all of them have been updated to support ARC. If you need to work with a class that doesn t support ARC and you still want to use ARC in your project, you can set a compiler flag for the file in question and assign it the value -fno -objc -arc, as shown in Figure 1-1.

5 Creating Your Personal Library 5 Figure 1-1 Interface Builder Because you are an experienced programmer, you know that Interface Builder is a part of Xcode that enables you to create and configure the UI elements of your project. Personally, I don t like working with Interface Builder because I like to have complete control over all aspects of the UI by means of code. The side effect, however, is that a large amount of my code is UI-related code. To keep the source code listings focused on the subject in most of the examples, Interface Builder is used to create the user interface and the Assistant Editor is used to create the IBAction and IBOutlets. Starting a New Project Start Xcode, create a new project using the Single View Application Project template, and name it MyPersonalLibrary using the configuration settings as shown in Figure 1-2. Figure 1-2

6 6 CHAPter 1 Creating a Personal Library The Class Prefix field will help you to follow Apple s coding guidelines because each class within your project needs to have a unique name. When you create the project you can use this field to define your default class prefix, which will be used when you are creating a new class. Although Apple s guidelines advise using a three-character prefix, I always use a two-character prefix the abbreviation of my company name, YourDeveloper so I choose YD as a default prefix for my classes. When you click the Next button, you will be asked to select a file location to store the project, and at the bottom of the screen you will see a checkbox that says Create Local git Repository for This Project, as shown in Figure 1-3. Check the option to create the local git repository and click the Create button to create the project with the chosen configuration. Figure 1-3 USINg a Local git RepoSItory When you select the option to create a local git repository, Xcode creates this repository for you automatically, which enables you to use version control on your project. With version control, Xcode keeps track of changes in your source code, enabling you to revert to a version, commit changes, compare versions, and so on. If you are using a server based subversion system (SVN) to manage your source control you don t require a local git repository since you will be using an SVN client or SVN commands to manage your sources. If you don t use a server based subversion system I strongly recommend to check the Create Local git Repository option when creating a new project. After the project is created, you ll see two classes in the project: the YDAppDelegate class and the YDViewController class. Both classes are created by default by Xcode. You also see a YDViewController.xib file, which is an Interface Builder file. Configuring Your Project It s good practice to use groups in your project structure to organize different elements like images, sounds, classes, views, helpers, and so on, so start by creating some groups under the MyPersonalLibrary node. Create the following groups: Externals Categories CrashHandler Helpers

7 Creating Your Personal Library 7 Definitions Images VC Because a group is only a container and not a physical folder on your filesystem, you should also create these folders on the filesystem under your project root folder. Because there will be a lot of repetitive tasks in all the applications you develop, and you still need the flexibility to switch functionalities on and off without recoding and copying and pasting parts of code, create a configuration file as follows: In the Project Explorer, navigate to the Definitions group and select New File from the context menu. Create a C header file called YDConstants.h as shown in Figures 1-4 and 1-5. Figure 1-4 Figure 1-5

8 8 CHAPter 1 Creating a Personal Library Defining Constants The Personal Library you are developing contains functionality for registration of a user, login of a user, and a settings controller. In addition to that you ll be implementing a crash handler. Implement the code as shown in Listing 1-1 in your YDConstants.h file. ListINg 1-1: Chapter1/MyPersonalLibrary/YDConstants.h #import <Foundation/Foundation.h> // My application switches #define bydactivategpsonstartup YES #define bydregistrationrequired YES #define bydloginrequired NO #define bydshowloginafterregistration YES #define bydinstallcrashhandler YES //keys that are used to store data #define #define #define #define Using the Configuration You can store settings using the NSUserDefaults class. Because you can store or change individual settings in many different places in your application, it s important to first synchronize the object to make sure modifications are presented with the correct value. Next, create a helper class that will give you some static methods to read and write values using the NSUserDefaults class. In the Project Explorer, navigate to the Helpers group and select File New from the context menu. Create a new Objective-C class named YDConfigurationHelper that inherits from NSObject, as shown in Listing 1-2. ListINg 1-2: Chapter1/MyPersonalLibrary/YDConfigurationHelper.h #import YDConfigurationHelper : NSObject +(void)setapplicationstartupdefaults; +(BOOL)getBoolValueForConfigurationKey:(NSString *)_objectkey; +(NSString *)getstringvalueforconfigurationkey:(nsstring *)_objectkey; +(void)setboolvalueforconfigurationkey:(nsstring *) _objectkey withvalue:(bool)_boolvalue;

9 Creating Your Personal Library 9 +(void)setstringvalueforconfigurationkey:(nsstring *) _objectkey withvalue:(nsstring *)_value; The YDConfigurationHelper class in Listing 1-3 contains a few static methods to help you access the NSUserDefaults object. It contains get and set methods for NSString values and BOOL values to make life a lot easier. ListINg 1-3: Chapter1/MyPersonalLibrary/YDConfigurationHelper.m #import YDConfigurationHelper +(void)setapplicationstartupdefaults NSUserDefaults *defaults = [NSUserDefaults standarduserdefaults]; [defaults synchronize]; [defaults setbool:no forkey:bydfirstlaunch]; [defaults setbool:no forkey:bydauthenticated]; [defaults synchronize]; +(BOOL)getBoolValueForConfigurationKey:(NSString *)_objectkey //create an instance of NSUserDefaults NSUserDefaults *defaults = [NSUserDefaults standarduserdefaults]; [defaults synchronize]; //let's make sure the object is synchronized return [defaults boolforkey:_objectkey]; +(NSString *)getstringvalueforconfigurationkey:(nsstring *)_objectkey //create an instance of NSUserDefaults NSUserDefaults *defaults = [NSUserDefaults standarduserdefaults]; [defaults synchronize]; //let's make sure the object is synchronized if ([defaults stringforkey:_objectkey] == nil ) //I don't want a (null) returned else return [defaults stringforkey:_objectkey]; +(void)setboolvalueforconfigurationkey:(nsstring *) _objectkey withvalue:(bool)_boolvalue NSUserDefaults *defaults = [NSUserDefaults standarduserdefaults]; [defaults synchronize]; //let's make sure the object is synchronized continues

10 10 CHAPter 1 Creating a Personal Library ListINg 1-3 (continued) [defaults setbool:_boolvalue forkey:_objectkey]; [defaults synchronize];//make sure you're synchronized again +(void)setstringvalueforconfigurationkey:(nsstring *) _objectkey withvalue:(nsstring *)_value NSUserDefaults *defaults = [NSUserDefaults standarduserdefaults]; [defaults synchronize]; //let's make sure the object is synchronized [defaults setvalue:_value forkey:_objectkey]; [defaults synchronize];//make sure you're synchronized again The getstringvalueforconfigurationkey: method is testing for a null value and returns an empty NSString instead of the null value. The reason is that in case you want to retrieve a value and assign it to the text property of a UILabel, you don t want to display (null). Importing the Header File As you know, when you want to use a header definition file in your application you need to import it using the #import "YDConstants.h" statement. This is not really convenient to repeat in each of your subsequent classes and ViewControllers. Each application, however, also has a precompiled header file that is applicable for the complete application. You can find this under the Supporting Files group in the Project Explorer; it is called MyPersonalLibrary-Prefix.pch. If you import a header file here, it s globally available. Add the import statements here for the YDConstants and YDConfigurationHelper header files, as shown in Listing 1-4. ListINg 1-4: Chapter1/MyPersonalLibrary/MyPersonalLibrary-Prefix.pch #import <Availability.h> #ifdef OBJC #import "YDConstants.h" #import"ydconfigurationhelper.h" #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #endif In the next section, you create a login, a registration, and a setting ViewController.

11 Registration Login 11 RegIStration LogIN Many applications require the user to register and log in, or log in only. If the user management is handled externally, you can ask a user to register in different ways. You can either ask for credentials like an e mail address or a username and a password, or what you see a lot nowadays you can ask the user to register via Facebook. Facebook registration is covered in depth in Chapter 14, Social Media Integration, and in that chapter, you will extend your Personal Library. Introducing the ios Keychain Services The ios Keychain Services provide you with a secure storage solution for passwords, keys, certificates, notes, and custom data on the user s device. In your Personal Library you ll be using the ios Keychain Services to store the password the user enters during the registration process you ll develop later. To make interaction with the ios Keychain Services more accessible, Apple has released a KeyChainItemWrapper class that will provide you with a higher-level API to work with the keychain. You can download a sample project including the KeyChainItemWrapper class that you need in your Personal Library from GenericKeychain/Listings/Classes_KeychainItemWrapper_h.html. Download the sample project from the URL and navigate to its files using Finder. In your Xcode project use the Project Explorer to navigate to the Externals group, select New Group from the context menu, and name it KeyChain. Create a folder named keychain under the externals folder on your filesystem. Copy the KeychainItemWrapper.h and KeychainItemWrapper.m files from the download folder to your projects folder by using drag-and-drop. Xcode will prompt you to choose the options for adding these files. Make the same choices as shown in Figure 1-6. Figure 1-6

12 12 CHAPter 1 Creating a Personal Library This KeychainItemWrapper class has not been developed for ARC, and for that reason you must set the fno objc arc compiler flag for the KeyChainItemWrapper.m file as already shown in Figure 1-1. For more information about KeyChain Services programming, please visit 01introduction/introduction.html. To be able to work with the Keychain Services using the KeychainItemWrapper class, you also need to add a reference to the Security.framework. Creating Registration Logic Your user registration screen may look different in each application because the design of each application will be different; nevertheless, you can standardize a part of the registration logic because you ll always have to follow certain steps: Verify if the user has registered before so you don t need to present the registration view again. If the user has registered before, define what subsequent processes are required; for example, present a login view or load data from a web service. You already have defined a constant called bydregistrationrequired in the YDConstants header file, which you can use in your application delegate to check if you need to present a ViewController to capture the registration credentials. Using the Project Explorer, navigate to the VC group and select New File from the context menu to create a UIViewController subclass called YDRegistrationViewController as shown in Figure 1-7. Figure 1-7 In this YDRegistrationViewController class, you need to set up a delegate that will notify the delegate ancestor with the result of the registration process. Use Interface Builder and the Assistant Editor to create a user interface with a UILabel, two UITextFields, and two UIButton objects. The YDRegistrationViewController.xib file will look like Figure 1-8.

13 Registration Login 13 Figure 1-8 The YDRegistrationViewController.h code is shown in Listing 1-5. ListINg 1-5: Chapter1/MyPersonalLibrary/YDRegistrationViewController.h #import YDRegistrationViewControllerDelegate <NSObject> -(void)registeredwithsuccess; -(void)registeredwitherror; YDRegistrationViewController : (nonatomic, assign) id<ydregistrationviewcontrollerdelegate> (weak, nonatomic) IBOutlet UITextField (weak, nonatomic) IBOutlet UITextField *passwordfield; - (IBAction)registerUser:(UIButton *)sender; - (IBAction)cancelRegistration:(UIButton *)sender; In YDRegistrationViewController.m, implement the registeruser: and cancelregistration: methods as shown in Listing 1-6. The registeruser: method first hashes the entered password into an MD5 string and then stores it in the keychain.

14 14 CHAPter 1 Creating a Personal Library ListINg 1-6: Chapter1/MyPersonalLibrary/YDRegistrationViewController.m #import "YDRegistrationViewController.h" #import "NSString+MD5.h" #import YDRegistrationViewController delegate; - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) // Custom initialization return self; - (void)viewdidload [super viewdidload]; // Do any additional setup after loading the view from its nib. - (void)didreceivememorywarning [super didreceivememorywarning]; // Dispose of any resources that can be recreated. - (IBAction)registerUser:(UIButton *)sender if (([self.namefield.text length]== 0 ) ([self.passwordfield.text length] == 0)) UIAlertView *alert = [[UIAlertView alloc] message:@"both fields are mandatory" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; [alert show]; else KeychainItemWrapper* keychain = [[KeychainItemWrapper alloc] initwithidentifier:@"ydappname" accessgroup:nil]; [keychain setobject:self.namefield.text forkey:( bridge id)ksecattraccount]; [keychain setobject:[self.passwordfield.text MD5] forkey:( bridge id)ksecvaluedata]; //reading back a value from the keychain for comparison //get username [keychain objectforkey:( bridge id)ksecattraccount]); //get password [keychain objectforkey:( bridge id)ksecvaluedata]);

15 Registration Login 15 [YDConfigurationHelper setboolvalueforconfigurationkey: bydregistered withvalue:yes]; [self.delegate registeredwithsuccess]; //or //[self.delegate registeredwitherror]; - (IBAction)cancelRegistration:(UIButton *)sender [self.delegate cancelregistration]; Initializing Data Each application requires some default settings that are applicable during the launch of the application. For that reason, in this section you learn how to initialize application defaults. Initializing Application Defaults So far you ve been working on creating a Personal Library that contains reusable and configurable code so you don t have to write the same code in each of your applications. You ve been using the NSUserDefaults class via the YDConfigurationHelper class you defined to store settings and results of operations. The first time your application launches, none of these values are set. To support the initialization of your defaults, the YDConfigurationHelper class has a static method called setapplication- StartupDefaults. In the implementation, you set the initial value of each property to control your application s logic at the first launch of an application, as in this example: +(void)setapplicationstartupdefaults NSUserDefaults *defaults = [NSUserDefaults standarduserdefaults]; [defaults synchronize]; [defaults setbool:no forkey:bydfirstlaunch]; [defaults setbool:no forkey:bydauthenticated]; [defaults synchronize]; You also may want to delete keychain items if they are left over from a previous install. This is also an ideal place if you need to create, for example, some special directories outside the bundle, so during further processing in your application you don t have to test each time if a directory exists. The purpose of the bydfirstlaunch key is to support the fact that this initialization code is being called only once. The following code snippet explains how you should call this method in the YDAppDelegate application: didfinishwithlaunchingoptions: method. It tests if the stored value returns YES, and in that case it calls setapplicationstartupdefaults, which sets the value to NO. if (![YDConfigurationHelper getboolvalueforconfigurationkey:bydfirstlaunch]) [YDConfigurationHelper setapplicationstartupdefaults];

16 16 CHAPter 1 Creating a Personal Library Creating Login Logic It is nice that a user can now register, but you also need to support the fact that a registered user can log in. As a first step, create a new ViewController that serves as the ViewController for entering a username and a password. Create a new YDLoginViewController that inherits from UIViewController and code it like in Listing 1-7. Like in the YDRegistrationViewController, you define a protocol that can be used by your delegate so your delegate object will be notified with the result of the login process. Three methods are called depending on the result of the login process. ListINg 1-7: Chapter1/MyPersonalLibrary/YDLoginViewController.h #import YDLoginViewControllerDelegate <NSObject> -(void)loginwithsuccess; -(void)loginwitherror; YDLoginViewController : (weak, nonatomic) IBOutlet UITextField (weak, nonatomic) IBOutlet UITextField (nonatomic, assign) id<ydloginviewcontrollerdelegate> delegate; - (IBAction)loginUser:(UIButton *)sender; - (IBAction)cancelLogin:(UIButton *)sender; The implementation of the YDLoginViewController is shown in Listing 1-8. ListINg 1-8: Chapter1/MyPersonalLibrary/YDLoginViewController.m #import "YDLoginViewController.h" #import "YDLoginViewController.h" #import "NSString+MD5.h" #import YDLoginViewController delegate; - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil self = [super initwithnibname:nibnameornil bundle:nibbundleornil];

17 Registration Login 17 if (self) // Custom initialization return self; - (void)viewdidload [super viewdidload]; // Do any additional setup after loading the view from its nib. - (void)didreceivememorywarning [super didreceivememorywarning]; // Dispose of any resources that can be recreated. - (IBAction)loginUser:(UIButton *)sender if (([self.namefield.text length]== 0 ) ([self.passwordfield.text length] == 0)) [self showerrorwithmessage:@"both fields are mandatory!"]; else KeychainItemWrapper* keychain = [[KeychainItemWrapper alloc] initwithidentifier:@"ydappname" accessgroup:nil]; if ([self.namefield.text isequaltostring: [keychain objectforkey:( bridge id)ksecattraccount]]) if ([[self.passwordfield.text MD5] isequaltostring:[keychain objectforkey: ( bridge id)ksecvaluedata]]) [self.delegate loginwithsuccess]; else [self showerrorwithmessage:@"password not correct."]; else [self showerrorwithmessage:@"name not correct."]; - (IBAction)cancelLogin:(UIButton *)sender [self.delegate logincancelled]; -(void)showerrorwithmessage:(nsstring *)msg UIAlertView *alert = [[UIAlertView alloc] initwithtitle:@"error" continues

18 18 CHAPter 1 Creating a Personal Library ListINg 1-8 (continued) [alert show]; message:msg delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; In the loginuser: method you see that the first check performed is if both fields have been entered with data. Next, the logic checks if the username is stored and, if so, if the password stored in the keychain is equal to the one that has been entered. The YDLoginViewController.xib file should look something like Figure 1-9. Figure 1-9 Securing Passwords In your YDRegistrationViewController, you accept a value for the username and for the password and store it in the keychain of the device. Many developers still store the username and password using the NSUserDefaults class, which is not a secure solution. This is not a very secure solution because the password is stored in plaintext, and the NSUserDefaults object is not 100 percent safe and can be hacked. To make your Personal Library more secure, implement a category of NSString that creates an MD5 hashed value of the password and store it in the keychain; the only safe place on the device to store critical data. In the Project Explorer, navigate to the Categories group and select New File from the context menu. Select Objective-C Category from the template list as shown in Figure 1-10.

19 Registration Login 19 Figure 1-10 Click the Next button, and in the next screen enter MD5 as the name of the category you are creating. From the Category On drop-down list, select NSString as shown in Figure Figure 1-11 The header file is shown in Listing 1-9. ListINg 1-9: Chapter1/MyPersonalLibrary/NSString+MD5 header #import NSString (MD5) - (NSString *)MD5;

20 20 CHAPter 1 Creating a Personal Library The implementation of your category is shown in Listing 1-10 and the explanation is in the code. ListINg 1-10: Chapter1/MyPersonalLibrary /NSString+MD5 implementation #import "NSString+MD5.h" #import NSString (MD5) - (NSString*)MD5 // Create pointer to the string as UTF8 const char *ptr = [self UTF8String]; // Create byte array of unsigned chars unsigned char md5buffer[cc_md5_digest_length]; // Create 16 bytes MD5 hash value, store in buffer CC_MD5(ptr, strlen(ptr), md5buffer); // Convert unsigned char buffer to NSString of hex values NSMutableString *output = [NSMutableString stringwithcapacity:cc_md5_digest_length * 2]; for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) [output appendformat:@"%02x",md5buffer[i]]; return output; In this category you import the <CommonCrypto/CommonDigest.h> header file. To do this, you must add the Security.framework to your project if you haven t already done that when adding the KeychainItemWrapper class. Storing the Password in a Keychain Apple has developed a keychain wrapper class that makes it easy for you to work with the keychain. The KeychainItemWrapper classes are part of the download of this book and are taken directly from Apple s developer portal. This KeychainItemWrapper class has not been developed for ARC, and for that reason you must set the fno objc arc compiler flag for the KeyChainItemWrapper.m file as shown earlier in Figure 1-1. Crash Management Despite all your programming efforts and extensive test processes, your application still might crash. There can be many different reasons for an application to crash, and sometimes it may not even relate to your application at all. In this section you learn about the kinds of crashes that happen and how to implement a crash handler that shows a UIAlertView with a standard message just before the app crashes, so your user knows the application is crashing and might be less irritated.

21 Crash Management 21 The two main reasons for a crash are: Memory leaks Over-releasing objects Memory leaks are most often caused by not releasing your objects. UIImageView, UIImage, and UIWebView are consuming a lot of memory; they definitely need to be released at the right time. Over-releasing happens when you try to access an object that is already released. USINg Instruments Instruments is a performance, analysis, and testing tool for dynamically tracing and profiling ios and OS X code. It s important to have a good understanding of Instruments and how it will help you in improving the quality of your code, by identifying memory leaks, giving you insight into memory consumption, and many other performance-relevant measures. Please visit apple.com/library/ios/#documentation/developertools/conceptual/ InstrumentsUserGuide/Introduction/Introduction.html for the complete documentation on Instruments. You can use Instruments and profile your application to identify memory leaks. You should use the Zombie instrument to identify access to an object that is already released (also known as a zombie). Understanding Crashes At run time, the application s signal handling can, by default, launch six different standard signals in case an application crashes. These signals are: SIGABRT: An abnormal termination SIGFPE: A floating-point exception SIGILL: An invalid instruction SIGINT: An interactive attention request sent to the application SIGSEGV: Access to an invalid memory address SIGTERM: Termination request sent to the application In the next section, you build a global exception handler that captures the signal and presents a UIAlertView to notify the user. Implementing a Crash Handler Create a new class called YDCrashHandler as shown in Listing 1-11.

22 22 CHAPter 1 Creating a Personal Library ListINg 1-11: Chapter1/MyPersonalLibrary/YDCrashHandler.h #import YDCrashHandler : NSObject BOOL dismissed; void InstallCrashExceptionHandler(); The implementation of the class is shown in Listing The class installs an NSSetUncaughtExceptionHandler for each of the available signals. If an exception occurs, the handler is invoked and accesses all modes in the current RunLoop. The process is killed and the back trace is read into an NSDictionary and passed to the handleexception method that presents a UIAlertView. ListINg 1-12: Chapter1/MyPersonalLibrary/YDCrashHandler.m #import "YDCrashHandler.h" #include <libkern/osatomic.h> #include <execinfo.h> NSString * const YDCrashHandlerSignalExceptionName NSString * const YDCrashHandlerSignalKey NSString * const YDCrashHandlerAddressesKey volatile int32_t UncaughtExceptionCount = 0; const int32_t UncaughtExceptionMaximum = 10; const NSInteger UncaughtExceptionHandlerSkipAddressCount = 4; const NSInteger UncaughtExceptionHandlerReportAddressCount = YDCrashHandler + (NSArray *)backtrace void* callstack[128]; int frames = backtrace(callstack, 128); char **strs = backtrace_symbols(callstack, frames); int i; NSMutableArray *backtrace = [NSMutableArray arraywithcapacity:frames]; for ( i = UncaughtExceptionHandlerSkipAddressCount; i < UncaughtExceptionHandlerSkipAddressCount + UncaughtExceptionHandlerReportAddressCount; i++) [backtrace addobject:[nsstring stringwithutf8string:strs[i]]]; free(strs);

23 Crash Management 23 return backtrace; - (void)alertview:(uialertview *)analertview clickedbuttonatindex:(nsinteger)anindex //if (anindex == 0) // dismissed = YES; // - (void)handleexception:(nsexception *)exception UIAlertView *thisalert = [[UIAlertView alloc] initwithtitle:@"sorry" message:@"an unexpected event happened causing the application to shutdown." delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; [thisalert show]; CFRunLoopRef runloop = CFRunLoopGetCurrent(); CFArrayRef allmodes = CFRunLoopCopyAllModes(runLoop); while (!dismissed) for (NSString *mode in (NSArray *)CFBridgingRelease(allModes)) CFRunLoopRunInMode((CFStringRef)CFBridgingRetain(mode), 0.001, false); CFRelease(allModes); NSSetUncaughtExceptionHandler(NULL); signal(sigabrt, SIG_DFL); signal(sigill, SIG_DFL); signal(sigsegv, SIG_DFL); signal(sigfpe, SIG_DFL); signal(sigbus, SIG_DFL); signal(sigpipe, SIG_DFL); if ([[exception name] isequal:ydcrashhandlersignalexceptionname]) kill(getpid(), [[[exception userinfo] objectforkey:ydcrashhandlersignalkey] intvalue]); else [exception raise]; continues

24 24 CHAPter 1 Creating a Personal Library ListINg 1-12 (continued) void HandleException(NSException *exception) int32_t exceptioncount = OSAtomicIncrement32(&UncaughtExceptionCount); if (exceptioncount > UncaughtExceptionMaximum) return; NSArray *callstack = [YDCrashHandler backtrace]; NSMutableDictionary *userinfo = [NSMutableDictionary dictionarywithdictionary:[exception userinfo]]; [userinfo setobject:callstack forkey:ydcrashhandleraddresseskey]; [[[YDCrashHandler alloc] init] performselectoronmainthread:@selector(handleexception:) withobject: [NSException exceptionwithname:[exception name] reason:[exception reason] userinfo:userinfo] waituntildone:yes]; void SignalHandler(int signal) int32_t exceptioncount = OSAtomicIncrement32(&UncaughtExceptionCount); if (exceptioncount > UncaughtExceptionMaximum) return; NSMutableDictionary *userinfo = [NSMutableDictionary dictionarywithobject:[nsnumber numberwithint:signal] forkey:ydcrashhandlersignalkey]; NSArray *callstack = [YDCrashHandler backtrace]; [userinfo setobject:callstack forkey:ydcrashhandleraddresseskey]; [[[YDCrashHandler alloc] init] performselectoronmainthread:@selector(handleexception:) withobject: [NSException

25 Crash Management 25 exceptionwithname:ydcrashhandlersignalexceptionname reason: [NSString %d was raised.", signal] userinfo: [NSDictionary dictionarywithobject:[nsnumber numberwithint:signal] forkey:ydcrashhandlersignalkey]] waituntildone:yes]; void InstallCrashExceptionHandler() NSSetUncaughtExceptionHandler(&HandleException); signal(sigabrt, SignalHandler); signal(sigill, SignalHandler); signal(sigsegv, SignalHandler); signal(sigfpe, SignalHandler); signal(sigbus, SignalHandler); signal(sigpipe, SignalHandler); Your Personal Library is now ready to be used. Open your YDAppDelegate.h file and implement the code as shown in Listing ListINg 1-13: Chapter1/MyPersonalLibrary/YDAppDelegate.h #import <UIKit/UIKit.h> #import "YDRegistrationViewController.h" #import YDAppDelegate : UIResponder <UIApplicationDelegate, YDLoginViewControllerDelegate, (strong, nonatomic) UIWindow (strong, nonatomic) YDViewController (strong, nonatomic) YDLoginViewController (strong, nonatomic) YDRegistrationViewController *registrationvc; Open your YDAppDelegate.m implementation file and write the code as shown in Listing The application: didfinishlaunchingwithoptions: method first checks if the YDCrashHandler needs to be installed. Next, it checks if the application runs for the first time, and if so, it sets the application startup defaults using the YDConfigurationHelper class. Next, it follows a logic that tests whether or not registration is required. If the previous test returns true, a second test is performed to see if a user registration has been executed before. If registration

26 26 CHAPter 1 Creating a Personal Library needs to be done, the YDRegistrationViewController is presented and the delegate implementation checks if the YDLoginViewController needs to be presented. After the login process has completed with success, the YDMainViewController is presented. The complete implementation is shown in Listing ListINg 1-14: Chapter1/MyPersonalLibrary/YDAppDelegate.m #import "YDAppDelegate.h" #import "YDViewController.h" #import YDAppDelegate - (void)installydcrashhandler InstallCrashExceptionHandler(); - (BOOL)application:(UIApplication *)application didfinishlaunchingwithoptions: (NSDictionary *)launchoptions if (bydinstallcrashhandler) [self performselector:@selector(installydcrashhandler) withobject:nil afterdelay:0]; self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; if (![YDConfigurationHelper getboolvalueforconfigurationkey:bydfirstlaunch]) [YDConfigurationHelper setapplicationstartupdefaults]; if (bydactivategpsonstartup) //Start your CLLocationManager here if you're application needs the GPS if (bydregistrationrequired &&![YDConfigurationHelper getboolvalueforconfigurationkey:bydregistered]) //Create an instance of your RegistrationViewcontroller self.registrationvc =[[YDRegistrationViewController alloc] init]; //Set the delegate self.registrationvc.delegate=self; self.window = [[UIWindow alloc] initwithframe: [[UIScreen mainscreen] bounds]]; self.window.rootviewcontroller = _registrationvc; self.window.backgroundcolor = [UIColor clearcolor]; [self.window makekeyandvisible];

27 Crash Management 27 else // you arrive here if either the registration is not required or yet achieved if (bydloginrequired) self.loginvc= [[YDLoginViewController alloc] init]; self.loginvc.delegate=self; self.window = [[UIWindow alloc] initwithframe: [[UIScreen mainscreen] bounds]]; self.window.rootviewcontroller = _loginvc; self.window.backgroundcolor = [UIColor clearcolor]; [self.window makekeyandvisible]; else self.viewcontroller= [[YDViewController alloc] init]; self.window.rootviewcontroller =self.viewcontroller; [self.window makekeyandvisible]; #pragma Registration Delegates -(void)registeredwitherror //called from RegistrationViewcontroller if registration failed -(void)registeredwithsuccess //called from RegistrationViewcontroller if the registration with success // if (bydshowloginafterregistration) self.loginvc = [[YDLoginViewController alloc] init]; self.loginvc.delegate=self; self.window = [[UIWindow alloc] initwithframe: [[UIScreen mainscreen] bounds]]; self.window.rootviewcontroller = self.loginvc; self.window.backgroundcolor = [UIColor clearcolor]; [self.window makekeyandvisible]; else self.viewcontroller= [[YDViewController alloc] init]; self.window.rootviewcontroller =self.viewcontroller; [self.window makekeyandvisible]; -(void)cancelregistration //called from RegistrationViewcontroller if cancel is pressed continues

28 28 CHAPter 1 Creating a Personal Library ListINg 1-14 (continued) #pragma Login delegates -(void)loginwithsuccess //called when login with success self.viewcontroller= [[YDViewController alloc] init]; self.window.rootviewcontroller =self.viewcontroller; [self.window makekeyandvisible]; -(void)loginwitherror //called when login with error -(void)logincancelled //called when login is cancelled Summary In this chapter you created a configurable Personal Library that you can use as a starting point for your applications. This Personal Library supports the following features: A single location for configuration settings A registration process with a ViewController A login process with a ViewController Storing values in user defaults Securing password storage by MD5 encryption and keychain storage A Settings ViewController that enables you to use checkboxes to retrieve and store application settings A crash handler to avoid unexpected crashes of your application In the next chapter, you learn how to advance your applications using UITableView objects and customize them to your needs. After you understand the basics for working with UITableView objects, you develop a custom UITableView solution that results in a chat view controller, like the one used in imessage. Finally, you develop a custom UITableView that supports drill-down functionality to improve the user s experience.

Navigation bar (Xcode version 4.5.2) 1. Create a new project. From the Xcode menu, select File > New > Project

Navigation bar (Xcode version 4.5.2) 1. Create a new project. From the Xcode menu, select File > New > Project Navigation bar (Xcode version 4.5.2) 1. Create a new project. From the Xcode menu, select File > New > Project Choose the Single View Application template Click Next. In the Choose options for your new

More information

src3/bettertextfield/bettertextfield/appdelegate.h // AppDelegate.h // BetterTextField

src3/bettertextfield/bettertextfield/appdelegate.h // AppDelegate.h // BetterTextField src3/bettertextfield/bettertextfield/appdelegate.h 1 1 1 1 AppDelegate.h BetterTextField Created by Tommy MacWilliam on 3/7/ Copyright (c) 2012 MyCompanyName. All rights reserved. #import

More information

lectures/2/src2/nib1/nib1/appdelegate.h // AppDelegate.h // Nib1 // David J. Malan // Harvard University //

lectures/2/src2/nib1/nib1/appdelegate.h // AppDelegate.h // Nib1 // David J. Malan // Harvard University // lectures/2/src2/nib1/nib1/appdelegate.h 1 1 1 1 1 1 1 1 1 2 AppDelegate.h Nib1 David J. Malan Harvard University malan@harvard.edu Demonstrates a Single View Application implemented with a nib, plus IBAction

More information

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar Design Patterns MSc in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

More information

iphone App Basics iphone and ipod touch Development Fall 2009 Lecture 5

iphone App Basics iphone and ipod touch Development Fall 2009 Lecture 5 iphone App Basics iphone and ipod touch Development Fall 2009 Lecture 5 Questions? Announcements Assignment #1 due this evening by 11:59pm Remember, if you wish to use a free late you must email me before

More information

OVERVIEW. Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net

OVERVIEW. Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net OVERVIEW Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net Microsoft MVP for 4 years C#, WinForms, WPF, Silverlight Joined Cynergy about

More information

Designing iphone Applications

Designing iphone Applications Designing iphone Applications 4 Two Flavors of Mail 5 Organizing Content 6 Organizing Content 6 Organizing Content 6 Organizing Content 6 Organizing Content Focus on your user s data 6 Organizing Content

More information

Integrating Game Center into a BuzzTouch 1.5 app

Integrating Game Center into a BuzzTouch 1.5 app into a BuzzTouch 1.5 app This tutorial assumes you have created your app and downloaded the source code; created an App ID in the ios Provisioning Portal, and registered your app in itunes Connect. Step

More information

Multitasking and Background Execution

Multitasking and Background Execution Multitasking and Background Execution Fall, 2012 Prof. Massimiliano "Max" Pala pala@nyu.edu Introduction Spawning Threads and Tasks Background Execution User hits 'home' button the app is sent in the background

More information

Objectives. Submission. Register for an Apple account. Notes on Saving Projects. Xcode Shortcuts. CprE 388 Lab 1: Introduction to Xcode

Objectives. Submission. Register for an Apple account. Notes on Saving Projects. Xcode Shortcuts. CprE 388 Lab 1: Introduction to Xcode Objectives Register for an Apple account Create an application using Xcode Test your application with the iphone simulator Import certificates for development Build your application to the device Expand

More information

Document Version Date: 1st March, 2015

Document Version Date: 1st March, 2015 7 Minute Fitness: ios(swift) Application Document Version 1.0.1 Date: 1st March, 2015 2 [7 MINUTE FITNESS: APP DOCUMENTATION] Important Notes:... 5 AppDelegate Class Reference... 6 Tasks... 6 Instance

More information

IOS - TEXT FIELD. Use of Text Field. Important Properties of Text Field. Updating Properties in xib

IOS - TEXT FIELD. Use of Text Field. Important Properties of Text Field. Updating Properties in xib IOS - TEXT FIELD http://www.tutorialspoint.com/ios/ios_ui_elements_text_field.htm Copyright tutorialspoint.com Use of Text Field A text field is a UI element that enables the app to get user input. A UITextfield

More information

AVAudioPlayer. avtouch Application

AVAudioPlayer. avtouch Application AVAudioPlayer avtouch Application iphone Application Index 1. iphone Application 1) iphone Application 2) iphone Application Main Method 3) iphone Application nib(.xib) 2. avtouch Application 1) avtouch

More information

HPE AppPulse Mobile. Software Version: 2.1. Adding AppPulse Mobile to Your ios App

HPE AppPulse Mobile. Software Version: 2.1. Adding AppPulse Mobile to Your ios App HPE AppPulse Mobile Software Version: 2.1 Adding AppPulse Mobile to Your ios App Document Release Date: November 2015 Contents How to Add HP AppPulse Mobile to Your ios App 3 Advanced Options 7 Crash Stack

More information

Registering for the Apple Developer Program

Registering for the Apple Developer Program It isn t necessary to be a member of the Apple Developer Program if you don t intend to submit apps to the App Stores, or don t need the cloud-dependent features. We strongly recommend joining, though,

More information

Your First ios 7 App. Everything you need to know to build and submit your first ios app. Ash Furrow

Your First ios 7 App. Everything you need to know to build and submit your first ios app. Ash Furrow Your First ios 7 App Everything you need to know to build and submit your first ios app. Ash Furrow This book is for sale at http://leanpub.com/your-first-ios-app This version was published on 2014-09-13

More information

ITP 342 Advanced Mobile App Dev. Memory

ITP 342 Advanced Mobile App Dev. Memory ITP 342 Advanced Mobile App Dev Memory Memory Management Objective-C provides two methods of application memory management. 1. In the method described in this guide, referred to as manual retain-release

More information

Intro to Native ios Development. Dave Koziol Arbormoon Software, Inc.

Intro to Native ios Development. Dave Koziol Arbormoon Software, Inc. Intro to Native ios Development Dave Koziol Arbormoon Software, Inc. About Me Long time Apple Developer (20 WWDCs) Organizer Ann Arbor CocoaHeads President & ios Developer at Arbormoon Software Inc. Wunder

More information

ios Core Data Example Application

ios Core Data Example Application ios Core Data Example Application The Core Data framework provides an abstract, object oriented interface to database storage within ios applications. This does not require extensive knowledge of database

More information

Why Model-View-Controller?

Why Model-View-Controller? View Controllers Why Model-View-Controller? Ever used the word spaghetti to describe code? Clear responsibilities make things easier to maintain Avoid having one monster class that does everything Why

More information

Topics in Mobile Computing

Topics in Mobile Computing Topics in Mobile Computing Workshop 1I - ios Fundamental Prepared by Y.H. KWOK What is ios? From Wikipedia (http://en.wikipedia.org/wiki/ios): ios is an operating system for iphone, ipad and Apple TV.

More information

Stanford CS193p. Developing Applications for ios Fall Stanford CS193p. Fall 2013

Stanford CS193p. Developing Applications for ios Fall Stanford CS193p. Fall 2013 Developing Applications for ios -14 Today What is this class all about? Description Prerequisites Homework / Final Project ios Overview What s in ios? MVC Object-Oriented Design Concept Objective C (Time

More information

CS193P: HelloPoly Walkthrough

CS193P: HelloPoly Walkthrough CS193P: HelloPoly Walkthrough Overview The goal of this walkthrough is to give you a fairly step by step path through building a simple Cocoa Touch application. You are encouraged to follow the walkthrough,

More information

View Controller Lifecycle

View Controller Lifecycle View Controller Lifecycle View Controllers have a Lifecycle A sequence of messages is sent to them as they progress through it Why does this matter? You very commonly override these methods to do certain

More information

The MVC Design Pattern

The MVC Design Pattern The MVC Design Pattern The structure of iphone applications is based on the Model-View-Controller (MVC) design pattern because it benefits object-oriented programs in several ways. MVC based programs tend

More information

My First iphone App (for Xcode version 6.4)

My First iphone App (for Xcode version 6.4) My First iphone App (for Xcode version 6.4) 1. Tutorial Overview In this tutorial, you re going to create a very simple application on the iphone or ipod Touch. It has a text field, a label, and a button

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer About the Tutorial ios is a mobile operating system developed and distributed by Apple Inc. It was originally released in 2007 for the iphone, ipod Touch, and Apple TV. ios is derived from OS X, with which

More information

iphone Programming Touch, Sound, and More! Norman McEntire Founder Servin Flashlight CodeTour TouchCount CodeTour

iphone Programming Touch, Sound, and More! Norman McEntire Founder Servin Flashlight CodeTour TouchCount CodeTour iphone Programming Touch, Sound, and More! Norman McEntire Founder Servin 1 Legal Info iphone is a trademark of Apple Inc. Servin is a trademark of Servin Corporation 2 Welcome Welcome! Thank you! My promise

More information

iphone Programming Patrick H. Madden SUNY Binghamton Computer Science Department

iphone Programming Patrick H. Madden SUNY Binghamton Computer Science Department iphone Programming Patrick H. Madden SUNY Binghamton Computer Science Department pmadden@acm.org http://optimal.cs.binghamton.edu General Outline Overview of the tools, and where to get more information

More information

Mobile Application Development

Mobile Application Development Mobile Application Development Lecture 13 Introduction to ObjectiveC Part II 2013/2014 Parma Università degli Studi di Parma Lecture Summary Object creation Memory management Automatic Reference Counting

More information

Objective-C and COCOA Applications

Objective-C and COCOA Applications Objective-C and COCOA Applications Fall, 2012 Prof. Massimiliano "Max" Pala pala@nyu.edu Overview X-Code IDE Basics Objective-C Classes Methods Invocations Important Types Memory Management Protocols Exceptions

More information

Announcement. Final Project Proposal Presentations and Updates

Announcement. Final Project Proposal Presentations and Updates Announcement Start Final Project Pitches on Wednesday Presentation slides dues by Tuesday at 11:59 PM Email slides to cse438ta@gmail.com Extensible Networking Platform 1 1 - CSE 438 Mobile Application

More information

ITP 342 Mobile App Development. Data Persistence

ITP 342 Mobile App Development. Data Persistence ITP 342 Mobile App Development Data Persistence Persistent Storage Want our app to save its data to persistent storage Any form of nonvolatile storage that survives a restart of the device Want a user

More information

IPHONE DEVELOPMENT. Getting Started with the iphone SDK

IPHONE DEVELOPMENT. Getting Started with the iphone SDK IPHONE DEVELOPMENT Getting Started with the iphone SDK OBJECTIVE-C The Big Picture STRICT SUPERSET OF C The Objective C Language Any C stuff applies Standard libs are here (time, sqrt etc) The C Language

More information

Social Pinboard: ios(swift) Application

Social Pinboard: ios(swift) Application Social Pinboard: ios(swift) Application Document Version 1.0.1 Date: 15 th May, 2015 2 [SOCIAL PINBOARD: APP DOCUMENTATION] Important Notes:... 5 AppDelegate Class Reference... 6 Tasks... 6 Instance Methods...

More information

App SandBox Directory

App SandBox Directory Data Persistence Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 App SandBox Directory

More information

lecture 10 UI/UX and Programmatic Design cs : spring 2018

lecture 10 UI/UX and Programmatic Design cs : spring 2018 lecture 10 UI/UX and Programmatic Design cs198-001 : spring 2018 1 Announcements custom app progress form due before lab (~1 minute) will be released after lecture only 2 labs left (both very important)

More information

imate: ios Application

imate: ios Application imate: ios Application Document Version 1.0.1 Date: 27 th May, 2014 2 [IMATE: IOS APPLICATION] Contents AppDelegate Class Reference... 4 Tasks... 4 Properties... 4 Instance Methods... 4 ChatMenuViewController

More information

Step 1: Open Xcode and select Create a new Xcode Project from the Welcome to Xcode menu.

Step 1: Open Xcode and select Create a new Xcode Project from the Welcome to Xcode menu. In this tutorial we are going to build a simple calculator using buttons that are all linked together using the same method. We will also add our own method to the source code to create some additional

More information

ITP 342 Mobile App Development. Data Persistence

ITP 342 Mobile App Development. Data Persistence ITP 342 Mobile App Development Data Persistence Persistent Storage Want our app to save its data to persistent storage Any form of nonvolatile storage that survives a restart of the device Want a user

More information

Objective-C Primer. iphone Programmer s Association. Lorenzo Swank September 10, 2008

Objective-C Primer. iphone Programmer s Association. Lorenzo Swank September 10, 2008 Objective-C Primer iphone Programmer s Association Lorenzo Swank September 10, 2008 Disclaimer Content was blatantly and unapologetically stolen from the WWDC 2007 Fundamentals of Cocoa session, as well

More information

Assignment II: Foundation Calculator

Assignment II: Foundation Calculator Assignment II: Foundation Calculator Objective The goal of this assignment is to extend the CalculatorBrain from last week to allow inputting variables into the expression the user is typing into the calculator.

More information

Xcode Release Notes. Apple offers a number of resources where you can get Xcode development support:

Xcode Release Notes. Apple offers a number of resources where you can get Xcode development support: Xcode Release Notes This document contains release notes for Xcode 5 developer preview 4. It discusses new features and issues present in Xcode 5 developer preview 4 and issues resolved from earlier Xcode

More information

iphone Application Tutorial

iphone Application Tutorial iphone Application Tutorial 2008-06-09 Apple Inc. 2008 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any

More information

Contents. iphone Training. Industry Trainers. Classroom Training Online Training ON-DEMAND Training. Read what you need

Contents. iphone Training. Industry Trainers. Classroom Training Online Training ON-DEMAND Training. Read what you need iphone Training Contents About iphone Training Our ios training classes can help you get off to a running start in iphone, ipod and ipad app development. Learn from expert Objective-C developers with years

More information

Corrections and version notes

Corrections and version notes Last updated 7 th May, 2014 Programming apps for the iphone Corrections and version notes Please feel free to email Graeme (gbsummers@graemesummers.info) for additional help or clarification on any of

More information

Widget Tour. iphone and ipod touch Development Fall 2009 Lecture 7

Widget Tour. iphone and ipod touch Development Fall 2009 Lecture 7 Widget Tour iphone and ipod touch Development Fall 2009 Lecture 7 Questions? Announcements Assignment #2 due Tonight by 11:59pm Today s Topics Controls Buttons Switches Sliders Segmented Controls Text

More information

epicurious Anatomy of an ios app Robert Tolar Haining June 25, 2010 ConvergeSE

epicurious Anatomy of an ios app Robert Tolar Haining June 25, 2010 ConvergeSE epicurious Anatomy of an ios app Robert Tolar Haining June 25, 2010 ConvergeSE + = Prototype iphone ipad Why iphone apps Simplicity Control Speed Revenue Epicurious Defined as a Recipe Utility Cookbook

More information

Porting Objective-C to Swift. Richard Ekle

Porting Objective-C to Swift. Richard Ekle Porting Objective-C to Swift Richard Ekle rick@ekle.org Why do we need this? 1.2 million apps in the ios App Store http://www.statista.com/statistics/276623/numberof-apps-available-in-leading-app-stores/

More information

Login with Amazon. Getting Started Guide for ios apps

Login with Amazon. Getting Started Guide for ios apps Login with Amazon Getting Started Guide for ios apps Login with Amazon: Getting Started Guide for ios Copyright 2017 Amazon.com, Inc., or its affiliates. All rights reserved. Amazon and the Amazon logo

More information

ios: Objective-C Primer

ios: Objective-C Primer ios: Objective-C Primer Jp LaFond Jp.LaFond+e76@gmail.com TF, CS76 Announcements n-puzzle feedback this week (if not already returned) ios Setup project released Android Student Choice project due Tonight

More information

View Concepts. iphone Application Programming Lecture 4: User Interface Design. SDK provide many types of Views to show your content

View Concepts. iphone Application Programming Lecture 4: User Interface Design. SDK provide many types of Views to show your content View Concepts iphone Application Programming Lecture 4: User Interface Design SDK provide many types of Views to show your content At run-time Views are organized as a tree Chat Wacharamanotham Media Computing

More information

AdFalcon ios SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

AdFalcon ios SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group AdFalcon ios SDK 4.1.0 Developer's Guide AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group Table of Contents 1 Introduction... 3 Prerequisites... 3 2 Install AdFalcon SDK... 4 2.1 Use CocoaPods

More information

My First iphone App. 1. Tutorial Overview

My First iphone App. 1. Tutorial Overview My First iphone App 1. Tutorial Overview In this tutorial, you re going to create a very simple application on the iphone or ipod Touch. It has a text field, a label, and a button. You can type your name

More information

Monday, 1 November The ios System

Monday, 1 November The ios System The ios System System Overview System Overview System Overview System Overview System Overview System Overview Foundation Classes (Useful) Foundation Framework Value and collection classes User defaults

More information

Announcements. Today s Topics

Announcements. Today s Topics Announcements Lab 2 is due tonight Lab 3 is posted Due next Wednesday Sept 30 th 1 Extensible - CSE 436 Software Networking Engineering Platform Workshop 1 Today s Topics Designing iphone Applica;ons Model-

More information

News- ipad: ios(swift) Application

News- ipad: ios(swift) Application News- ipad: ios(swift) Application Document Version 1.0.1 Date: 9 th Nov, 2014 2 [NEWS- IPAD: APP DOCUMENTATION] Important Notes:... 6 AppDelegate Class Reference... 7 Tasks... 7 Instance Methods... 7

More information

InterfaceBuilder and user interfaces

InterfaceBuilder and user interfaces ES3 Lab 2 InterfaceBuilder and user interfaces This lab InterfaceBuilder Creating components Linking them to your code Adding buttons, labels, sliders UITableView Creating a tableview Customizing cells

More information

CS193P - Lecture 3. iphone Application Development. Custom Classes Object Lifecycle Autorelease Properties

CS193P - Lecture 3. iphone Application Development. Custom Classes Object Lifecycle Autorelease Properties CS193P - Lecture 3 iphone Application Development Custom Classes Object Lifecycle Autorelease Properties 1 Announcements Assignments 1A and 1B due Wednesday 1/13 at 11:59 PM Enrolled Stanford students

More information

Your First iphone OS Application

Your First iphone OS Application Your First iphone OS Application General 2010-03-15 Apple Inc. 2010 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form

More information

Design Phase. Create a class Person. Determine the superclass. NSObject (in this case)

Design Phase. Create a class Person. Determine the superclass. NSObject (in this case) Design Phase Create a class Person Determine the superclass NSObject (in this case) 8 Design Phase Create a class Person Determine the superclass NSObject (in this case) What properties should it have?

More information

ITP 342 Mobile App Dev. Fundamentals

ITP 342 Mobile App Dev. Fundamentals ITP 342 Mobile App Dev Fundamentals Objective-C Classes Encapsulate data with the methods that operate on that data An object is a runtime instance of a class Contains its own in-memory copy of the instance

More information

Objective-C. Stanford CS193p Fall 2013

Objective-C. Stanford CS193p Fall 2013 New language to learn! Strict superset of C Adds syntax for classes, methods, etc. A few things to think differently about (e.g. properties, dynamic binding) Most important concept to understand today:

More information

Your First iphone Application

Your First iphone Application Your First iphone Application General 2009-01-06 Apple Inc. 2009 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form

More information

AVAudioRecorder & System Sound Services

AVAudioRecorder & System Sound Services AVAudioRecorder & System Sound Services Dept. of Multimedia Science, Sookmyung Women s University. prof. JongWoo Lee Index AVAudioRecorder? - (AudioRecorder) System Sound Service? - (SysSound) AVAudioRecorder

More information

CLOCK4 TUTORIAL VERY SIMPLE HELLO WORLD COCOA APPLICATION

CLOCK4 TUTORIAL VERY SIMPLE HELLO WORLD COCOA APPLICATION http:clanmills.com Page 1/8 CLOCK4 TUTORIAL VERY SIMPLE HELLO WORLD COCOA APPLICATION Life in a new programming environment has to start somewhere. Everybody knows the hello world application written in

More information

Assignment I Walkthrough

Assignment I Walkthrough Assignment I Walkthrough Objective Reproduce the demonstration (building a calculator) given in class. Materials By this point, you should have been sent an invitation to your sunet e-mail to join the

More information

Building Mapping Apps for ios With Swift

Building Mapping Apps for ios With Swift Building Mapping Apps for ios With Swift Jeff Linwood This book is for sale at http://leanpub.com/buildingmappingappsforioswithswift This version was published on 2017-09-09 This is a Leanpub book. Leanpub

More information

Notifications. Mobile Application Development in ios School of EECS Washington State University Instructor: Larry Holder

Notifications. Mobile Application Development in ios School of EECS Washington State University Instructor: Larry Holder Notifications Mobile Application Development in ios School of EECS Washington State University Instructor: Larry Holder Mobile Application Development in ios 1 Outline Alerts Internal notifications Local

More information

Xcode Release Notes. Apple offers a number of resources where you can get Xcode development support:

Xcode Release Notes. Apple offers a number of resources where you can get Xcode development support: Xcode Release Notes This document contains release notes for Xcode 5 developer preview 5. It discusses new features and issues present in Xcode 5 developer preview 5 and issues resolved from earlier Xcode

More information

1 Build Your First App. The way to get started is to quit talking and begin doing. Walt Disney

1 Build Your First App. The way to get started is to quit talking and begin doing. Walt Disney 1 Build Your First App The way to get started is to quit talking and begin doing. Walt Disney Copyright 2015 AppCoda Limited All rights reserved. Please do not distribute or share without permission. No

More information

Life Cycle. Chapter Explore the Game Application. Understanding the Views in a Game

Life Cycle. Chapter Explore the Game Application. Understanding the Views in a Game 3 Chapter Explore the Game Application Life Cycle There is more to a game than just the fun parts. Almost all of the games on the market, and definitely the big titles, involve multiple views and a reasonably

More information

ITP 342 Mobile App Dev. Unit Testing

ITP 342 Mobile App Dev. Unit Testing ITP 342 Mobile App Dev Unit Testing Testing Xcode provides you with capabilities for extensive software testing. Testing your projects enhances robustness, reduces bugs, and speeds the acceptance of your

More information

COMP327 Mobile Computing Session: Lecture Set 1a - Swift Introduction and the Foundation Framework Part 2

COMP327 Mobile Computing Session: Lecture Set 1a - Swift Introduction and the Foundation Framework Part 2 COMP327 Mobile Computing Session: 2018-2019 Lecture Set 1a - Swift Introduction and the Foundation Framework Part 2 73 Other Swift Guard Already seen that for optionals it may be necessary to test that

More information

Developing Applications for ios

Developing Applications for ios Developing Applications for ios Lab 2: RPN Calculator App (1 of 3) Radu Ionescu raducu.ionescu@gmail.com Faculty of Mathematics and Computer Science University of Bucharest Task 1 Task: Create a new application

More information

Mobile Development - Lab 2

Mobile Development - Lab 2 Mobile Development - Lab 2 Objectives Illustrate the delegation mechanism through examples Use a simple Web service Show how to simply make a hybrid app Display data with a grid layout Delegation pattern

More information

Announcements. Today s Topics

Announcements. Today s Topics Announcements Lab 2 is due tonight by 11:59 PM Late policy is 10% of lab total per day late So -7.5 points per day late for lab 2 Labs 3 and 4 are posted on the course website Extensible Networking Platform

More information

CS 47. Beginning iphone Application Development

CS 47. Beginning iphone Application Development CS 47 Beginning iphone Application Development Introductions Who, why, which? Shameless Plug: LoudTap Wifi Access (If it works..) SSID: Stanford Username/password: csp47guest Expectations This is a programming

More information

Developing Applications for ios

Developing Applications for ios Developing Applications for ios Lecture 7: View Controller Lifecycle and UIKit Radu Ionescu raducu.ionescu@gmail.com Faculty of Mathematics and Computer Science University of Bucharest Content View Controller

More information

Principles of Programming Languages. Objective-C. Joris Kluivers

Principles of Programming Languages. Objective-C. Joris Kluivers Principles of Programming Languages Objective-C Joris Kluivers joris.kluivers@gmail.com History... 3 NeXT... 3 Language Syntax... 4 Defining a new class... 4 Object identifiers... 5 Sending messages...

More information

Stanford CS193p. Developing Applications for ios. Fall Stanford CS193p. Fall 2011

Stanford CS193p. Developing Applications for ios. Fall Stanford CS193p. Fall 2011 Developing Applications for ios Today UI Element of the Week UIToolbar ipad Split View Popover Universal (iphone + ipad) Application Demo Friday Section AVFoundation framework - Capturing and manipulating

More information

ITP 342 Mobile App Dev. Alerts

ITP 342 Mobile App Dev. Alerts ITP 342 Mobile App Dev Alerts Alerts UIAlertController replaces both UIAlertView and UIActionSheet, thereby unifying the concept of alerts across the system, whether presented modally or in a popover.

More information

Objective-C ICT/7421ICTNathan. René Hexel. School of Information and Communication Technology Griffith University.

Objective-C ICT/7421ICTNathan. René Hexel. School of Information and Communication Technology Griffith University. Objective-C 2.0 2501ICT/7421ICTNathan René Hexel School of Information and Communication Technology Griffith University Semester 1, 2012 Outline Fast Enumeration and Properties 1 Fast Enumeration and Properties

More information

Collections. Fall, Prof. Massimiliano "Max" Pala

Collections. Fall, Prof. Massimiliano Max Pala Collections Fall, 2012 Prof. Massimiliano "Max" Pala pala@nyu.edu Overview Arrays Copy and Deep Copy Sets Dictionaries Examples Arrays Two Classes NSArray and NSMutableArray (subclass of NSArray) int main(int

More information

View Concepts. iphone Application Programming Lecture 4: User Interface Design. SDK provide many types of Views to show your content

View Concepts. iphone Application Programming Lecture 4: User Interface Design. SDK provide many types of Views to show your content View Concepts iphone Application Programming Lecture 4: User Interface Design SDK provide many types of Views to show your content At run-time Views are organized as a tree Chat Wacharamanotham Media Computing

More information

Review (Basic Objective-C)

Review (Basic Objective-C) Classes Header.h (public) versus Implementation.m (private) @interface MyClass : MySuperclass... @end (only in header file) @interface MyClass()... @end (only in implementation file) @implementation...

More information

CS193p Spring 2010 Thursday, April 29, 2010

CS193p Spring 2010 Thursday, April 29, 2010 CS193p Spring 2010 Announcements You should have received an e-mail by now If you received e-mail approving enrollment, but are not in Axess, do it! If you have any questions, please ask via e-mail or

More information

ITP 342 Mobile App Dev. Connections

ITP 342 Mobile App Dev. Connections ITP 342 Mobile App Dev Connections User Interface Interactions First project displayed information to the user, but there was no interaction. We want the users of our app to touch UI components such as

More information

Stanford CS193p. Developing Applications for ios. Spring Stanford CS193p. Spring 2012

Stanford CS193p. Developing Applications for ios. Spring Stanford CS193p. Spring 2012 Developing Applications for ios Today NSTimer and perform after delay Two delayed-action alternatives. More View Animation Continuation of Kitchen Sink demo Alerts and Action Sheets Notifying the user

More information

Data IAP 2010 iphonedev.csail.mit.edu edward benson / Thursday, January 14, 2010

Data IAP 2010 iphonedev.csail.mit.edu edward benson / Thursday, January 14, 2010 Data IAP 2010 iphonedev.csail.mit.edu edward benson / eob@csail.mit.edu Today Property Lists User Defaults Settings Panels CoreData Property Lists Today Add persistence. plist 1. Using Property Lists in

More information

Building GUIs with UIKit. Kevin Cathey

Building GUIs with UIKit. Kevin Cathey Building GUIs with UIKit Kevin Cathey Building GUIs with UIKit acm.uiuc.edu/macwarriors/devphone Building GUIs with UIKit What is UIKit? acm.uiuc.edu/macwarriors/devphone Building GUIs with UIKit What

More information

MVC and Interface Builder IAP 2010

MVC and Interface Builder IAP 2010 MVC and Interface Builder IAP 2010 iphonedev.csail.mit.edu edward benson / eob@csail.mit.edu Information-Driven Applications Application Flow UIApplication Main NIB Initialized UIAppDelegate - (void)applicationdidfinishlaunching:(uiapplication

More information

ReportPlus Embedded. ReportPlus Embedded - ios SDK Guide 1.0

ReportPlus Embedded. ReportPlus Embedded - ios SDK Guide 1.0 ReportPlus Embedded ios SDK Guide ReportPlus Embedded - ios SDK Guide 1.0 Disclaimer THE INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED AS IS WITHOUT ANY EXPRESS REPRESENTATIONS OF WARRANTIES. IN ADDITION,

More information

ITP 342 Mobile App Dev. Connections

ITP 342 Mobile App Dev. Connections ITP 342 Mobile App Dev Connections User Interface Interactions First project displayed information to the user, but there was no interaction. We want the users of our app to touch UI components such as

More information

1.1 Why Foxit Mobile PDF SDK is your choice Foxit Mobile PDF SDK Key features Evaluation...

1.1 Why Foxit Mobile PDF SDK is your choice Foxit Mobile PDF SDK Key features Evaluation... TABLE OF CONTENTS 1 Introduction to...2 1.1 Why is your choice... 2 1.2... 3 1.3 Key features... 4 1.4 Evaluation... 4 1.5 License... 5 1.6 About this Guide... 5 2 Getting Started...6 2.1 Requirements...

More information

View Controllers CPRE 388

View Controllers CPRE 388 View Controllers CPRE 388 View Controllers Manage views in model view controller design template. Many types: custom view controller; container view controller; modal view controller. Custom View controllers

More information

Advanced ios. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 20 11/01/2012

Advanced ios. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 20 11/01/2012 Advanced ios CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 20 11/01/2012 1 Goals of the Lecture Present a few additional topics and concepts related to ios programming persistence serialization

More information

QuickPrints SDK for ios Version 3.3 August 06, 2014

QuickPrints SDK for ios Version 3.3 August 06, 2014 Introduction The QuickPrints SDK for ios (ipod Touch, iphone, and ipad) is a static library that provides a set of APIs that can be used to submit a photo print order to a Walgreens store. This document

More information

Mobile Application Programming. Objective-C Classes

Mobile Application Programming. Objective-C Classes Mobile Application Programming Objective-C Classes Custom Classes @interface Car : NSObject #import Car.h + (int) viper; - (id) initwithmodel:(int)m; @implementation Car Point position; float velocity;

More information

ITP 342 Mobile App Dev. Table Views

ITP 342 Mobile App Dev. Table Views ITP 342 Mobile App Dev Table Views Table Views The most common mechanism used to display lists of data to the user Highly configurable objects that can be made to look practically any way you want them

More information