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".
  • Getting iPhone Location Information using the iOS 4 Core Location Framework - Techotopia
    CLLocationManager locationMgr CLLocationManager alloc init locationMgr desiredAccuracy kCLLocationAccuracyBest locationMgr delegate self locationMgr startUpdatingLocation With each location update an application delegate method named didUpdateToLocation is called by the location manager and passed information about the current location The above code also therefore assigns the current class as the location manager s delegate Configuring the Desired Location Accuracy google IOSBOX google The level of accuracy to which location information is to be tracked is specified via the desiredAccuracy property of the CLLocationManager object It is important to keep in mind when configuring this property that the greater the level of accuracy selected the greater the drain on the device battery An application should therefore never request a greater level of accuracy than is needed A number of predefined constant values are available for use when configuring this property kCLLocationAccuracyBestForNavigation Uses the highest possible level of accuracy augmented by additional sensor data This accuracy level is intended solely for use when the device is connected to an external power supply kCLLocationAccuracyBest The highest level of accuracy for devices running on battery power kCLLocationAccuracyNearestTenMeters Accurate to within 10 meters kCLLocationAccuracyHundredMeters Accurate to within 100 meters kCLLocationAccuracyKilometer Accurate to within one kilometer kCLLocationAccuracyThreeKilometers Accurate to within three kilometers Configuring the Distance Filter The default configuration for the location manager is to report updates whenever any changes are detected in the location of the device The distanceFilter property of the location manager allows applications to specify the amount of distance the device location must move before an update is triggered If for example the distance filter is set to 1000 meters the application will only receive a location update when the device travels 1000 meters or more from the location of the last update For example to specify a distance filter of 1500 meters locationMgr distanceFilter 1500 0f The distance filter may be cancelled thereby returning to the default setting using the kCLDistanceFilterNone constant locationMgr distanceFilter kCLDistanceFilterNone The Location Manager Delegate Location manager updates and errors result in calls to two delegate methods defined within the CLLocationManagerDelegate protocol Templates for the two delegate methods that must be implemented to comply with this protocol are as follows pragma mark pragma mark CLLocationManagerDelegate void locationManager CLLocationManager manager didUpdateToLocation CLLocation newLocation fromLocation CLLocation oldLocation Handle location updates void locationManager CLLocationManager manager didFailWithError NSError error Handle error Obtaining Location Information from CLLocation Objects Location information is passed through to the didUpdateLocation delegate method in the form of CLLocation objects A CLLocation object encapsulates the following data Latitude Longitude Horizontal Accuracy Altitude Altitude Accuracy Longitude and Latitude Longitude and latitude values are stored as type CLLocationDegrees and may be obtained from a CLLocation object as follows CLLocationDegrees currentLatitude location coordinate latitude CLLocationDegrees currentLongitude location coordinates longitude Accuracy Horizontal and vertical accuracy are stored in meters as CLLocationDistance values and may be accessed as follows CLLocation verticalAccuracy location verticalAccuracy CLLocation horizontalAccurcy location horizontalAccuracy Altitude The altitude value is stored in meters as type CLLocationDistance values and may be accessed from a CLLocation

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


  • An Example iOS 4 iPhone Location Application - Techotopia
    will be displayed to multiple levels of decimal points that require space beyond the default size of the label Establish a connection between the latitude outlet declared in the view controller and the corresponding user interface label by Ctrl clicking on the File s Owner icon and dragging the blue line to the label located to the right of the Latitude label Release the line and select the latitude outlet from the resulting menu Repeat this task to establish outlet connections of the remaining six data display labels The final step of the user interface design process is to connect the button object to the resetDistance action method This is achieved by selecting the button in the view window and displaying the Connections Inspector window Command 2 Click in the round circle to the right of the Touch Up Inside event and drag the line to the File s Owner entry in the documents window On releasing the mouse button select the resetDistance method from the resulting menu Save the design and exit from Interface Builder Creating the CLLocationManager Object The next task is to implement the code to create an instance of the CLLocationManager class Since this needs to occur when the application starts up an ideal location is in the view controller s viewDidLoad method Whilst making this code change it is also a good opportunity to add the necessary synthesize directives to the locationViewController m file import locationViewController h implementation locationViewController synthesize longitude latitude horizontalAccuracy verticalAccuracy altitude distance synthesize locationManager startLocation void viewDidLoad self locationManager CLLocationManager alloc init locationManager desiredAccuracy kCLLocationAccuracyBest locationManager delegate self locationManager startUpdatingLocation startLocation nil super viewDidLoad The above code creates a new CLLocationManager object instance and configures it to use the best accuracy setting It then declares itself as the application delegate for the object The location manager object is then instructed to begin updating location information via a call to the startUpdatingLocation method Since location tracking has just begun at this point the startLocation object is also set to nil Implementing the Action Method The button object in the user interface is connected to the resetDistance action method so the next task is to implement that action All this method needs to do is set the startlocation object to nil void resetDistance startLocation nil Implementing the Application Delegate Methods When the location manager detects a location change it calls the didUpdateToLocation delegate method Since the view controller was declared as the delegate for the location manager in the viewDidLoad method it is necessary to now implement this method pragma mark pragma mark CLLocationManagerDelegate void locationManager CLLocationManager manager didUpdateToLocation CLLocation newLocation fromLocation CLLocation oldLocation NSString currentLatitude NSString alloc initWithFormat g newLocation coordinate latitude latitude text currentLatitude NSString currentLongitude NSString alloc initWithFormat g newLocation coordinate longitude longitude text currentLongitude NSString currentHorizontalAccuracy NSString alloc initWithFormat g newLocation horizontalAccuracy horizontalAccuracy text currentHorizontalAccuracy NSString currentAltitude NSString alloc initWithFormat g newLocation altitude altitude text currentAltitude currentAltitude release NSString currentVerticalAccuracy NSString alloc initWithFormat g newLocation verticalAccuracy verticalAccuracy text currentVerticalAccuracy

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

  • Accessing the Camera and Photo Library from an iOS 4 iPhone Application - Techotopia
    when configuring this property Whether or not the user is permitted to perform editing before the image is passed on to the application is controlled via the allowsEditing boolean property The following code creates a UImagePickerController instance and configures it for camera use with movie and image support and editing allowed It then displays the controller and releases the controller object UIImagePickerController imagePicker UIImagePickerController alloc init imagePicker delegate self imagePicker sourceType UIImagePickerControllerSourceTypeCamera imagePicker mediaTypes NSArray arrayWithObjects NSString kUTTypeImage NSString kUTTypeMovie nil imagePicker allowsEditing YES self presentModalViewController imagePicker animated YES imagePicker release It should be noted that the above code also configured the current class as the delegate for the UIImagePickerController instance This is actually a key part of how the class works and is covered in the next section Configuring the UIImagePickerController Delegate When the user is presented with the UIImagePickerController object user interface the application essentially hands control to that object That being the case the controller needs some way to notify the application that the user has taken a photo recorded a video or made a library selection It does this by calling delegate methods The class that instantiates a UIImagePickerController instance should therefore declare itself as the object s delegate conform to the UIImagePickerControllerDelegate and UINavigationControllerDelegate protocols and implement the didFinishPickingMediaWithInfo and imagePickerControllerDidCancel methods When the user has selected or created media the didFinishPickingMediaWithInfo method is called and passed an NSDictionary object containing the media and associated data In the event that the user cancels the operation the imagePickerControllerDidCancel method is called In both cases it is the responsibility of the delegate method to dismiss the view controller void imagePickerController UIImagePickerController picker didFinishPickingMediaWithInfo NSDictionary info Code here to work with media self dismissModalViewControllerAnimated YES void imagePickerControllerDidCancel UIImagePickerController picker self dismissModalViewControllerAnimated YES The info argument passed to the didFinishPickingMediaWithInfo method is an NSDictionary object containing the data relating to the image or video created or selected by the user The first step is typically to identify the type of media NSString mediaType info objectForKey UIImagePickerControllerMediaType if mediaType isEqualToString NSString kUTTypeImage Media is an image else if mediaType isEqualToString NSString kUTTypeMovie Media is a video The original unedited image selected or photographed by the user may be obtained from the info dictionary as follows UIImage image info objectForKey UIImagePickerControllerOriginalImage Assuming that editing was enabled on the image picker controller object the edited version of image may be accessed via the UImagePickerControllerEditedImage dictionary key UIImage image info objectForKey UIImagePickerControllerEditedImage If the media is a video the URL to the recorded media may be accessed as follows NSURL url info objectForKey UIImagePickerControllerMediaURL Once the image or video URL has been obtained the application can optionally save the media to the library and either display the image to the user or play the video using the MPMoviePlayer class as outlined the chapter entitled Video Playback from within an iOS 4 iPhone Application Detecting Device Capabilities Not all iOS devices provide the same functionality iPhone model prior to the 3GS model for example

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

  • An Example iOS 4 iPhone Camera Application - Techotopia
    property nonatomic retain IBOutlet UIImageView imageView IBAction useCamera IBAction useCameraRoll end Designing the User Interface The next step in this tutorial is to design the user interface This is a very simple user interface consisting of an image view and two buttons Double click on the cameraViewContoller xib file to load it into the Interface Builder tool and drag and drop components from the Library window onto the view Position and size the components and set the text on the button so that the user interface resembles the following illustration Next Ctrl click on the File s Owner entry in the documents window and drag the resulting line to the UIImageView object in the view window Select the imageView outlet from the resulting menu Select the Camera button and display the connections inspector window Command 2 Click inside the circle to the right of the Touch Up Inside event and drag the line to the File s Owner entry Select the useCamera method from the resulting menu Repeat these steps to connect the Camera Roll button to the useCameraRoll action method Save the design and exit from Interface Builder Implementing the Action Methods The useCamera and useCameraRoll action methods now need to be implemented The useCamera method first needs to check that the device on which the application is running has a camera It then needs to create a UIImagePickerController instance assign the cameraViewController as the delegate for the object and define the media source as the camera Since we do not plan on handling videos the supported media types property is set to images only Finally the camera interface will be displayed and the UIImagePickerController object released The last task is to set the newMedia flag to YES to indicate that the image is new and is not an existing image from the camera roll Bringing all these requirements together gives us the following useCamera method void useCamera if UIImagePickerController isSourceTypeAvailable UIImagePickerControllerSourceTypeCamera UIImagePickerController imagePicker UIImagePickerController alloc init imagePicker delegate self imagePicker sourceType UIImagePickerControllerSourceTypeCamera imagePicker mediaTypes NSArray arrayWithObjects NSString kUTTypeImage nil imagePicker allowsEditing NO self presentModalViewController imagePicker animated YES imagePicker release newMedia YES The useCameraRoll method is remarkably similar to the previous method with the exception that the source of the image is declared to be UIImagePickerControllerSourceTypePhotoLibrary and the newMedia flag is set to NO since the photo is already in the library we don t need to save it again void useCameraRoll if UIImagePickerController isSourceTypeAvailable UIImagePickerControllerSourceTypeSavedPhotosAlbum UIImagePickerController imagePicker UIImagePickerController alloc init imagePicker delegate self imagePicker sourceType UIImagePickerControllerSourceTypePhotoLibrary imagePicker mediaTypes NSArray arrayWithObjects NSString kUTTypeImage nil imagePicker allowsEditing NO self presentModalViewController imagePicker animated YES imagePicker release newMedia NO Writing the Delegate Methods As described in Accessing the Camera and Photo Library from an iOS 4 iPhone Application in order to fully implement an instance of the image picker controller delegate protocol it is necessary to implement some delegate methods The most important method is the didFinishPickingMediaWithInfo which is called when the user has finished taking or selecting an image The code

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

  • Video Playback from within an iOS 4 iPhone Application - Techotopia
    select MediaPlayer framework and click on Add Declaring the Action Method The application user interface is going to consist of a single button which when pressed will initiate the movie playback process We therefore need to declare an action method called playMovie in our movieViewController h file It is also imperative that the MediaPlayer MediaPlayer h file be imported to avoid a catalog of unresolved references when the application is compiled import UIKit UIKit h import MediaPlayer MediaPlayer h interface movieViewController UIViewController IBAction playMovie end Once the changes have been made save the file before proceeding Designing the User Interface Double click on the movieViewController xib file to load it into Interface Builder Drag a single UIButton instance to the view window and change the text on the button to Play Movie With the button selected display the connections inspector window Command 2 click on the circle to the right of the Touch Up Inside event and drag the blue line to the File s Owner entry in the documents window From the resulting menu select the playMove action method Save the design and exit from Interface Builder Adding the Video File to the Project Resources Initially the video file to be displayed to the user is going to be bundled on the device with the application In a later section we will look at streaming a move from a remote network location Begin by finding a suitable movie file for inclusion in the application Any movie recorded by an iPhone will suffice for this purpose Copy the movie file to the system on which Xcode is running and name it movie mov In the main Xcode project window ctrl click on the Resources entry in the Groups Files panel and select Add New File Browse to the location of the movie mov file and add it to the project accepting the default settings on the import settings panel Implementing the Action Method The next step is to write the code for the action method so that the video is played to the user when the button is touched by the user The code for the method should be placed in the movieViewController m file as follows void playMovie NSURL url NSURL fileURLWithPath NSBundle mainBundle pathForResource movie ofType mov MPMoviePlayerController moviePlayer MPMoviePlayerController alloc initWithContentURL url NSNotificationCenter defaultCenter addObserver self selector selector moviePlayBackDidFinish name MPMoviePlayerPlaybackDidFinishNotification object moviePlayer moviePlayer controlStyle MPMovieControlStyleDefault moviePlayer shouldAutoplay YES self view addSubview moviePlayer view moviePlayer setFullscreen YES animated YES The above method constructs an NSURL object based on the video file that was added to the project resources This is then used in the creation of a new instance of the MPMoviePlayerController class A notification is then configured such that the moviePlaybackDidFinish method is called when the playback finishes Next properties are set to ensure that the standard movie controls are available to the user and that the movie automatically starts playing once it is ready Finally the movie player object is added as a subview to

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

  • Basic iOS 4 iPhone Animation using Core Animation - Techotopia
    assigned to the transform property of the UIView object For example to change the scale of a UIView object named myView by a factor of 2 in both height and width myView transform CGAffineTransformMakeScale 2 2 Similarly the UIView object may be rotated using the CGAffineTransformMakeRotation which takes as an argument the angle in radians by which the view is to be rotated The following code for example rotates a view by 90 degrees myView transform CGAffineTransformMakeRotation 90 M PI 180 The key point to keep in mind with transformations is that they become animated effects when performed within an animation block The transformations evolve over the duration of the animation and follow the specified animation curve in terms of timing Combining Transformations Two transformations may be combined to create a single transformation effect via a call to the CGAffineTransformConcat function This function takes as arguments the two transformation objects that are to be combined The result may then be assigned to the transform property of the UIView object to be transformed The following code fragment for example both scales and rotates a UIView object named myView CGAffineTransform scaleTrans CGAffineTransformMakeScale 2 2 CGAffineTransform rotateTrans CGAffineTransformMakeRotation angle M PI 180 myView transform CGAffineTransformConcat scaleTrans rotateTrans Affine transformations offer an extremely powerful and flexible mechanism for creating animations and it is just not possible to do justice to these capabilities in a single chapter In order to learn more about affine transformations a good starting place is the Transforms chapter of the Quartz 2D Programming Guide Creating the Animation Example Application The remainder of this chapter is dedicated to the creation of an iPhone application that demonstrates the use of Core Animation The end result is a simple application on which a blue square appears When the user touches a location on the screen the box moves to that location Through the use of affine transformations the box will rotate 180 degrees as it moves to the new location whilst also changing in size Begin by launching Xcode and creating a new View based iOS application named animate Implementing the Interface File For the purposes of this application we will need a UIView to represent the blue square and variables to contain the rotation angle and scale factor by which the square will be transformed These need to be declared in the animateViewController h file as follows import UIKit UIKit h interface animateViewController UIViewController UIView boxView float scaleFactor float angle property nonatomic retain UIView boxView end Once the changes are complete be sure to save the file prior to proceeding Drawing in the UIView Having declared the UIView reference we now need to initialize an instance object and draw a blue square located at a specific location on the screen We also need to initialize our scaleFactor and angle variables and add boxView as a subview of the application s main view object These tasks only need to be performed once when the application first starts up so a good location is

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

  • IPhone iOS 4 Development Essentials - Techotopia
    Second Table View Implementing the Functionality of the Second View Controller Popping the View Controller off the Navigation Controller Stack Adding the Navigation Code Using the UIPickerView and UIDatePicker Components in iOS 4 iPhone Applications The DatePicker and PickerView Components A DatePicker Example Designing the User Interface Coding the Date Picker Example Functionality Releasing Memory Building and Running the iPhone Date Picker Application An iOS 4 iPhone UIPickerView Example Creating the iOS 4 PickerView Project UIPickerView Delegate and DataSource The pickerViewController h File Designing the User Interface Initializing the Arrays Implementing the DataSource Protocol Implementing the Delegate Hiding the Keyboard Testing the Application Working with Directories on iOS 4 iPhone The Application Documents Directory The Objective C NSFileManager NSFileHandle and NSData Classes Understanding Pathnames in Objective C Creating an NSFileManager Instance Object Identifying the Current Working Directory Identifying the Documents Directory Identifying the Temporary Directory Changing Directory Creating a New Directory Deleting a Directory Listing the Contents of a Directory Getting the Attributes of a File or Directory Working with Files on iOS 4 iPhone Creating an NSFileManager Instance Checking if a File Exists Comparing the Contents of Two Files Checking if a File is Readable Writable Executable Deletable Moving Renaming a File Copying a File Removing a File Creating a Symbolic Link Reading and Writing Files with NSFileManager Working with Files using the NSFileHandle Class Creating an NSFileHandle Object NSFileHandle File Offsets and Seeking Reading Data from a File Writing Data to a File Truncating a File iOS 4 iPhone Directory Handling and File I O A Worked Example The Example iPhone Application Setting up the Application project Defining the Actions and Outlets Designing the User Interface Checking the Data File on Application Startup Implementing the Action Method Building and Running the Example iOS 4 iPhone Data Persistence using Archiving An Overview of Archiving The Archiving Example Application Implementing the Actions and Outlets Releasing Memory Designing the iPhone User Interface Checking for the Existence of the Archive File on Startup Archiving Object Data in the Action Method Testing the Application iOS 4 iPhone Database Implementation using SQLite What is SQLite Structured Query Language SQL Trying SQLite on MacOS X Preparing an iOS 4 Application Project for SQLite Integration Key SQLite Functions Declaring a SQLite Database Opening or Creating a Database Preparing and Executing a SQL Statement Creating a Database Table Extracting Data from a Database Table Closing a SQLite Database An Example SQLite based iOS 4 iPhone Application About the Example SQLite iPhone Application Creating and Preparing the SQLite Application Project Importing sqlite3 h and Declaring the Database Reference Creating the Outlets and Actions Releasing Memory Creating the Database and Table Implementing the Code to Save Data to the SQLite Database Implementing Code to Extract Data from the SQLite Database Designing the User Interface Building and Running the Application Working with iOS 4 iPhone Databases using Core Data The Core Data Stack Managed Objects Managed Object Context Managed Object Model Persistent Store Coordinator Persistent Object Store Defining an Entity

    Original URL path: http://www.techotopia.com/index.php?title=IPhone_iOS_4_Development_Essentials&oldid=22302 (2016-02-13)
    Open archived version from archive

  • Pages that link to "IPhone iOS 4 Development Essentials" - Techotopia
    iOS 4 App Development Essentials links Installing Xcode and the iOS 4 SDK links Creating a Simple iPhone iOS 4 App links Testing iOS 4 Apps on the iPhone Developer Certificates and Provisioning Profiles links The Basics of Objective C Programming iOS4 iPhone links The Basics of iPhone iOS 4 Object Oriented Programming in Objective C links An Overview of the iPhone iOS 4 Application Development Architecture links Creating an Interactive iOS 4 iPhone App links Writing iOS 4 Code to Hide the iPhone Keyboard links Understanding iPhone iOS 4 Views Windows and the View Hierarchy links IOS 4 iPhone Rotation View Resizing and Layout Handling links Creating an iOS 4 iPhone Multiview Application using the Tab Bar links Creating a Simple iOS 4 iPhone Table View Application links Creating a Navigation based iOS 4 iPhone Application using TableViews links Working with Directories on iOS 4 iPhone links Working with Files on iOS 4 iPhone links IOS 4 iPhone Directory Handling and File I O A Worked Example links IOS 4 iPhone Data Persistence using Archiving links IOS 4 iPhone Database Implementation using SQLite links An Example SQLite based iOS 4 iPhone Application links Working with iOS 4 iPhone Databases using Core Data links An iOS 4 iPhone Core Data Tutorial links An Overview of iOS 4 iPhone Multitouch Taps and Gestures links An Example iOS 4 iPhone Touch Multitouch and Tap Application links Detecting iOS 4 iPhone Touch Screen Gesture Motions links Drawing iOS 4 iPhone 2D Graphics with Quartz links An iOS 4 iPhone Graphics Drawing Tutorial using Quartz 2D links Integrating iAds into an iOS 4 iPhone App links An Overview of iOS 4 iPhone Multitasking links Scheduling iOS 4 iPhone Local Notifications links Getting iPhone Location Information using the iOS 4 Core Location Framework links An

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



  •