archive-com.com » COM » T » TECHOTOPIA.COM

Total: 1018

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Installing Xcode and the iPhone SDK - Techotopia
    then your current system is sadly unsuitable as a platform for iPhone app development Installing Xcode and the iPhone SDK The best way to obtain the latest versions of Xcode and the iPhone SDK is to download them from the Apple web site The URL to download Xcode is http developer apple com technology xcode html There are two forms of Xcode one for developing both Mac OS X and iPhone applications and the other solely for developing Mac OS X applications For the purposes of this book you will of course need the package that includes the iPhone SDK In order to download Xcode with the iPhone SDK you will need a Registered iPhone Developer account Fortunately membership is free and can be activated using your existing Apple account for example the one you use to buy music on iTunes Once you have registered you will gain access to the Apple Developer Connection web site where download links are provided for Xcode and the SDK on a variety of Mac OS X versions The download is over 2GB in size and will take a number of hours to complete depending on the speed of your internet connection The package takes the form of a disk image dmg file Once the download has completed a new window will open as follows displaying the contents of the dmg file If this window does not open by default it can be opened by clicking on the SDK disk drive icon on the desktop Initiate the installation by double clicking on the package icon the one that looks like an opening box and follow the instructions until you reach the Custom Install screen The default selections on this screen are adequate for most requirements so unless you have specific needs there is no

    Original URL path: http://www.techotopia.com/index.php/Installing_Xcode_and_the_iPhone_SDK (2016-02-13)
    Open archived version from archive


  • Creating a Simple iPhone App - Techotopia
    we will also need to put our own declarations and definitions In addition the xib files are the save files used by the Interface Builder tool to hold the user interface designs we will create Older versions of Interface Builder saved designs in files with a nib extension so these files even today are called NIB files Also present will be one or more files with a plist file extension These are Property List files that contain key value pair information For example the HelloWorld info plist file contains resource settings relating to items such as the language icon file executable name and app identifier Also listed are some frameworks that Xcode believes we will need during the development of our app Additional Frameworks can be added to the project by right clicking or Ctrl clicking on the Frameworks folder located in the left hand Groups and Files panel and selecting Add Existing Frameworks from the menu A list of available frameworks will be displayed from which you may select the framework you need When a source file is selected from the list in the main panel the contents of that file will appear in the panel below where it may then be edited To open the file in a separate editing window simply double click on the file in the list Creating the App User Interface Simply by the very nature of the environment in which they run iPhone apps are typically visually oriented As such a key component of just about any app involves a user interface through which the user will interact with the application and receive feedback Whilst it is possible to develop user interfaces by writing code to create and position items on the screen this is a complex and error prone process In recognition of this Apple provides a tool called Interface Builder that allows a user interface to be visual constructed by dragging and dropping components onto a canvas and setting properties to configure the appearance and behavior of those components Interface Builder was originally developed some time ago for developing Mac OS X applications but has now been updated to allow for the design of iPhone app user interfaces As mentioned in the preceding section Xcode pre created a number of files for our project some of which have a xib filename extension These are Interface Builder save files remember that they are called NIB files not XIB files The file we are interested in for our HelloWorld project is called HelloWorldViewController xib To load this file into Interface Builder simply double click on the file name in list Interface Builder will subsequently start up and display a number of windows as shown in the following figure The smaller dialog entitled HelloWorldViewController xib contains the key objects that make up the view controller for our user interface We will be looking at the other objects in window in later chapters For now the item of most interest to us is the View

    Original URL path: http://www.techotopia.com/index.php/Creating_a_Simple_iPhone_App (2016-02-13)
    Open archived version from archive

  • Testing Apps on the iPhone – Developer Certificates and Provisioning Profiles - Techotopia
    a button to Download the certificate Installing an iPhone Development Certificate Once a certificate has been requested and approved it must be installed on the development system so that Xcode can access it and use it to sign any applications you develop The first step in this process is to download the certificate from the iPhone Provisioning Portal by clicking on the Download button located on the certificates page outlined in the previous section Once the file has downloaded double click on it to load it into the Keychain Access tool The certificate will then be listed together with a status hopefully one that reads This certificate is valid Your certificate is now installed into your Keychain and you are ready to move on to the next step Assigning Devices Once you have a development certificate installed the next step is to specify which devices are to be used to test the apps you are developing This is achieved by entering the Unique Device identifier UDID for each device into the Provisioning Portal Note that Apple restricts developers to 100 devices per year The UDID for a device may be obtained either via Xcode or iTunes Begin by connecting the device your computer using the docking connector Once Xcode has launched the Organizer screen will appear displaying summary information about the device or may be opened by selecting Window Organizer The UDID is listed next to the Identifier label as illustrated in the following figure Alternatively launch iTunes select the device in the left hand pane and review the Summary information page One of the fields on this page will be labeled as Serial Number Click with the mouse on this number and it will change to display the UDID Having identified the UDIDs of any devices you plan to use for app testing select the Devices link located in the left hand panel of the iPhone Provisioning Portal and click on Add Devices in the resulting page On the Add Devices page enter a descriptive name for the device and the 40 character UDID In order to add more than one device at a time simply click on the button to create more input fields Once you have finished adding devices click on the Submit button The newly added devices will now appear on the main Devices page of the portal Creating an App ID The next step in the process is to create an App ID for each app that you create This ID allows your app to be uniquely identified within the Apple iPhone application infrastructure To create an App ID select the App IDs link in the provisioning portal and click on the New App ID button to display the Create App ID screen as illustrated below Enter a suitably descriptive name into the Description field and then make a Bundle Seed ID selection If you have not created any previous Seed IDs then leave the default Generate New selection unchanged If you have created a

    Original URL path: http://www.techotopia.com/index.php/Testing_Apps_on_the_iPhone_%E2%80%93_Developer_Certificates_and_Provisioning_Profiles (2016-02-13)
    Open archived version from archive

  • The Basics of Object Oriented Programming in Objective-C - Techotopia
    to accept more than one argument For example to define a method that accepts both the account number and account balance we could declare it as follows void setAccount long y andBalance double x Now that we have an understanding of the structure of method declarations within the context of the class interface definition we can extend our BankAccount class accordingly interface BankAccount NSObject double accountBalance long accountNumber void setAccount long y andBalance double x void setAccountBalance double x double getAccountBalance void setAccountNumber long y long getAccountNumber void displayAccountInfo end Having defined the interface we can now move on to defining the implementation of our class Declaring an Objective C Class Implementation The next step in creating a new class in Objective C is to write the code for the methods we have already declared This is performed in the implementation section of the class definition An outline implementation is structured as follows implementation NewClassName ClassMethods end In order to implement the methods we declared in the interface section therefore we need to write the following implementation BankAccount void setAccount long y andBalance double x accountBalance x accountNumber y void setAccountBalance double x accountBalance x double getAccountBalance return accountBalance void setAccountNumber long y accountNumber y long getAccountNumber return accountNumber void displayAccountInfo NSLog Account Number i has a balance of f accountNumber accountBalance end We are now at the point where we can write some code to work with our new BankAccount class Declaring Initializing and Releasing a Class Instance So far all we have done is define the blueprint for our class In order to do anything with this class we need to create instances of it The first step in this process is to declare a variable to store a pointer to the instance when it is created We do this as follows BankAccount account1 Having created a variable to store a reference to the class instance we can now allocate memory in preparation for initializing the class account1 BankAccount alloc In the above statement we are calling the alloc method of the BankAccount class note that alloc is a class method inherited from the parent NSObject class as opposed to an instance method created by us in the BankAccount class Having allocated memory for the class instance the next step is to initialize the instance by calling the init instance method account1 account1 init For the sake of economy of typing the above three statements are frequently rolled into a single line of code as follows BankAccount account1 BankAccount alloc init In the first step of this section we allocated memory for the creation of the class instance Good programming conventions dictate that memory allocated to a class instance should be released when the instance is no longer required Failure to do so can result in memory leaks such that the application will continue to use up system memory until none is left Those familiar with Java will be used to relying on the garbage collector to free

    Original URL path: http://www.techotopia.com/index.php/The_Basics_of_Object_Oriented_Programming_in_Objective-C (2016-02-13)
    Open archived version from archive

  • An Overview of the iPhone Application Development Architecture - Techotopia
    Similarly the View knows nothing about the data and logic model of the application Within the context of an object oriented programming environment such as the iPhone SDK and Objective C the Model View and Controller components are objects It is also worth pointing out that applications are not restricted to a single model view and controller In fact an app can consist of multiple view objects controller objects and model objects The way that a view controller object interacts with a Model is through the methods and properties exposed by that model object This in fact is no different from the way one object interacts with another in any object oriented programming environment In terms of the view controller s interactions with the view however things get a little more complicated In practice this is achieved using the Target Action pattern together with Outlets and Actions The Target Action pattern IBOutlets and IBActions When you create an iPhone app you will typically design the user interface the view using the Interface Builder tool and write the view controller and model code in Objective C using the Xcode code editor In the previous section looked briefly at how the view controller interacts with the model In this section we will look at how the view created in Interface Builder and our view controller code interact with each other When a user interacts with objects in the view for example touching and releasing a button control an event is triggered in this case the event is called a Touch up Inside event The purpose of the Target Action pattern is to allow you to specify what happens when such events are triggered In other words this how you connect the objects in the user interface you have designed in the Interface Builder tool to the back end Objective C code you have written in the Xcode environment Specifically this allows you to define which method of which controller object gets called when a user interacts in a certain way with a view object The process of wiring up a view object to call a specific method on a view controller object is achieved using something called an Action An action is a method defined within a view controller object that is designed to be called when an event is triggered in a view object This allows us to connect a view object created within a nib file using Interface Builder to the code that we have written in the view controller object This is one of the ways that we bridge the separation between the View and the Controller in our MVC design pattern As we will see in Creating an Interactive iPhone App action methods are declared using the IBAction keyword The opposite to an Action is the Outlet As previously described an Action allows a view object to call a method on a controller object An Outlet on the other hand allows a view controller object method to directly

    Original URL path: http://www.techotopia.com/index.php/An_Overview_of_the_iPhone_Application_Development_Architecture (2016-02-13)
    Open archived version from archive

  • Creating an Interactive iPhone App - Techotopia
    named UnitConverterViewController m Selecting the UnitConverterViewController h file in the main Xcode window will display the contents of the file in the editing window UnitConverterViewController h UnitConverter Created by Techotopia on 3 30 10 Copyright MyCompanyName 2010 All rights reserved import UIKit UIKit h interface UnitConverterViewController UIViewController end As we can see from the above code a new class called UnitConverterViewController has been created that is a subclass of the UIViewController class belonging to the UIKit framework The next step is to extend the subclass to include the two outlets and our action method We will begin by adding outlets for our text field and label objects by declaring variables and using the IBOutlet keyword import UIKit UIKit h interface UnitConverterViewController UIViewController UITextField tempText UILabel resultLabel property nonatomic retain IBOutlet UILabel resultString property nonatomic retain IBOutlet UITextField tempString end Next we need to declare the action that will be called when the user touches the Convert button in our user interface This is declared using the IBAction keyword import UIKit UIKit h interface UnitConverterViewController UIViewController UITextField tempText UILabel resultLabel property nonatomic retain IBOutlet UILabel resultLabel property nonatomic retain IBOutlet UITextField tempText IBAction convertTemp id sender end We have now declared that our View Controller class contains a method called convertTemp Having made that declaration we now need to implement the method in the implementation source file To do so select the UnitConverterViewController m file so that the contents appear in the editing pane import UnitConverterViewController h implementation UnitConverterViewController The designated initializer Override to perform setup that is required before the view is loaded id initWithNibName NSString nibNameOrNil bundle NSBundle nibBundleOrNil if self super initWithNibName nibNameOrNil bundle nibBundleOrNil Custom initialization return self Implement loadView to create a view hierarchy programmatically without using a nib void loadView Implement viewDidLoad to do additional setup after loading the view typically from a nib void viewDidLoad super viewDidLoad Override to allow orientations other than the default portrait orientation BOOL shouldAutorotateToInterfaceOrientation UIInterfaceOrientation interfaceOrientation Return YES for supported orientations return interfaceOrientation UIInterfaceOrientationPortrait void didReceiveMemoryWarning Releases the view if it doesn t have a superview super didReceiveMemoryWarning Release any cached data images etc that aren t in use void viewDidUnload Release any retained subviews of the main view e g self myOutlet nil void dealloc super dealloc end The first step is to instruct Objective C to synthesize accessor methods for our tempText and resultLabel objects and then to implement the convertTemp method The relevant section of the UnitConverterViewController m file should now read as follows import UnitConverterViewController h import UnitConverterViewController h implementation UnitConverterViewController synthesize resultLabel tempText void convertTemp id sender double farenheit tempText text doubleValue double celcius farenheit 32 1 8 NSString resultString NSString alloc initWithFormat Celcius f celcius resultLabel text resultString resultString release Before we proceed it is probably a good idea to pause and explain what is happening in the above code Those already familiar with Objective C however may skip the next few paragraphs In this file we are implementing the convertTemp method that

    Original URL path: http://www.techotopia.com/index.php/Creating_an_Interactive_iPhone_App (2016-02-13)
    Open archived version from archive

  • Understanding iPhone Views, Windows and the View Hierarchy - Techotopia
    or interact directly with the UIWindow object These windows may be created programmatically but are typically created automatically by Interface Builder when you design your user interface In the example applications we have created in previous chapters the UIWindow instance is contained in its own NIB file with the name MainWindow xib The View Hierarchy iPhone user interfaces are constructed using a hierarchical approach whereby different views are related through a parent child relationship At the top of this hierarchy sits the UIWindow object Other views are then added to the hierarchy If we take the example from the chapter entitled Creating an Interactive iPhone App we have a design that consists of a window a view a text field a button and a label The view hierarchy for this user interface would be drawn as illustrated in the following figure In this example the UIWindow object is the parent or superview of the UIView instance and the UIView is the child or subview of the UIWindow Similarly the text label and button objects are all subviews of the UIView A subview can only have one direct parent As shown in the above example however a superview may have multiple subviews In addition view hierarchies can be nested to any level of depth Consider for example the following hierarchy diagram The hierarchical structure of a user interface has significant implications for how the views appear and behave Visually subviews always appear on top of and within the visual frame of their corresponding parent The button in the above example therefore appears on top of the parent view in the running application Furthermore the resizing behavior of subviews in other words the way in which the views change size when the device is rotated is defined in relation to the parent view Superviews also have the ability to modify the positioning and size of their subviews If we were to design the above nested view hierarchy in Interface Builder it might appear as illustrated in the following figure In this example the UIWindow instance is not visible because it is fully obscured by the blue UIView1 instance Displayed on top of and within the frame of UIView1 are the UIButton1 UILabel and yellow UIView2 subviews Displayed on top of and within the frame of UIView2 are its respective subviews namely UIButton2 and UIImageView The view hierarchy also defines how events are handled when a user interacts with the interface essentially defining something called the responder chain If for example a subview receives an event that it cannot handle that event is passed up to the immediate superview If that superview is also unable to handle the event it is passed up to the next parent and so on until it reaches a level within the responder chain where it can be dealt with View Types google IOSBOX google Apple groups the various views included in the UIKit framework into a number of different categories The Window The UIWindow is the root

    Original URL path: http://www.techotopia.com/index.php/Understanding_iPhone_Views,_Windows_and_the_View_Hierarchy (2016-02-13)
    Open archived version from archive

  • Writing Code to Hide the iPhone Keyboard - Techotopia
    the textField outlet Save the design and exit from Interface Builder Hiding the Keyboard when the User Touches the Return Key The next step is to wire up our application so that the keyboard is dismissed when the user touches the keyboard Return key To do so we need to write a method that will resign the first responder on the text field in other words hide the keyboard when the Return key is pressed Begin by editing the hideKeyboardViewController h interface file to declare the method which we will name textFieldReturn import UIKit UIKit h interface hideKeyboardViewController UIViewController UITextField textField property nonatomic retain IBOutlet UITextField textField IBAction textFieldReturn id sender end Having declared the method we now need to implement it in the hideKeyboardViewController m implementation file import hideKeyboardViewController h implementation hideKeyboardViewController synthesize textField IBAction textFieldReturn id sender sender resignFirstResponder end google ADSDAQBOX FLOW google In the above method we are making a call to the resignFirstResponder method of the object that triggered the event The first responder is the object with which the user is currently interacting Having written the code for our method we now need to wire up our user interface so that it gets called at the appropriate time We will perform this task in Interface Builder so double click on the hideKeyboardViewController xib file to load the file once more Once Interface Builder has loaded select the text field in the view window and display the Connections Inspector window Tools Connections Inspector or Command 2 Click on the circle to the right of the Did End on Exit event drag the line to the File s Owner icon and select textFieldReturn from the list of available methods Save the design exit from Interface Builder and click on the Build and Run button in the Xcode toolbar When the application appears in the simulator select the text field so that the keyboard appears and then touch the Return key The keyboard should disappear from view Hiding the Keyboard when the User Taps the Background The second mechanism for hiding the keyboard involves wiring up an event to be called when the user touches the background view of the screen We will begin the process by writing the action method to perform this task From within Xcode select the hideKeyboardViewController h file and add a declaration for our new backgroundTouched action method import UIKit UIKit h interface hideKeyboardViewController UIViewController UITextField textField property nonatomic retain IBOutlet UITextField textField IBAction textFieldReturn id sender IBAction backgroundTouched id sender end Save the hideKeyboardViewController h before proceeding Next open the hideKeyboardViewController m file and implement the action by calling the resignFirstResponder method of our textField object import hideKeyboardViewController h implementation hideKeyboardViewController synthesize textField IBAction textFieldReturn id sender sender resignFirstResponder IBAction backgroundTouched id sender textField resignFirstResponder end Once the changes have been made be sure to save the file before proceeding Having written the code for our action method we now need to make sure it gets called when the user touches

    Original URL path: http://www.techotopia.com/index.php/Writing_Code_to_Hide_the_iPhone_Keyboard (2016-02-13)
    Open archived version from archive



  •