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".
  • Synchronizing iPad iOS 6 Key-Value Data using iCloud - Techotopia
    by another application instance This is achieved by setting up an observer on the NSUbiquitousKeyValueStore DidChangeExternallyNotification notification This notification is triggered when a change is made to any key value pair in a specified key value store and is passed an array of strings containing the keys that were changed together with an NSNumber indicating the reason for the change In the event that the available space for the key value storage has been exceeded this number will match the NSUbiquitousKeyValueStoreQuotaViolationChange constant value An iCloud Key Value Data Storage Example The remainder of this chapter is devoted to the creation of an application that uses iCloud key value storage to store a key with a string value using iCloud In addition to storing a key value pair the application will also configure an observer to receive notification when the value is changed by another application instance Begin the application creation process by launching Xcode and creating a new Single View Application project with the name and class prefix of iCloudKeys with Storyboard support and Automatic Reference Counting enabled Enabling the Application for iCloud Key Value Data Storage A mandatory step in the development of the application is to configure the appropriate iCloud entitlement This is achieved by selecting the application target at the top of the Xcode project navigator panel and selecting the Summary tab in the main panel Scroll down the summary information until the entitlements section comes into view and turn on the Entitlements Enable iCloud and iCloud Key Value Store options Figure 40 1 Once selected Xcode will create an entitlements file for the project named iCloudKeys entitlements containing the appropriate iCloud entitlements key value pairs Select the entitlements file from the project navigator and note the value assigned to the ubiquity kvstore identity key By default this is typically comprised of your team or individual developer ID combined with the application s Bundle identifier Any other applications that use the same value for the entitlement key will share access to the same iCloud based key value data stored by this application Designing the User Interface The application is going to consist of a text field into which a string may be entered by the user and a button which when selected will save the string to the application s iCloud key value data store Select the MainStoryboard storyboard file display the object library View Utilities Show Object Library and drag and drop the two objects into the view canvas Double click on the button object and change the text to Store Key The completed view should resemble Figure 40 2 Figure 40 2 Select the text field object in the view canvas display the Assistant Editor panel and verify that the editor is displaying the contents of the iCloudKeysViewController h file Ctrl click on the text field object and drag to a position just below the interface line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named

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


  • IOS 6 iPad Data Persistence using Archiving - Techotopia
    and presented to the user Begin by launching Xcode and create a new iOS iPad project named Archive using the Single View Application template with Storyboard support and Automatic Reference Counting enabled Once the main Xcode project window appears populated with the template files it is time to start developing the application Designing the User Interface The user interface for our application is going to consist of three UILabels three UITextFields and single UIButton Select MainStoryboard storyboard in the main Xcode project navigator and display the Object library panel View Utilities Show Object Library if it is not already visible Drag drop resize position and configure objects on the View window canvas until your design approximates that illustrated in Figure 41 1 Figure 41 1 Select the top most text field object in the view canvas display the Assistant Editor panel and verify that the editor is displaying the contents of the ArchiveViewController h file Ctrl click on the text field object again and drag to a position just below the interface line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named name Repeat the above steps to establish outlet connections for the remaining text fields to properties named address and phone respectively Ctrl click on the button object and drag the line to the area immediately beneath the newly created outlets in the Assistant Editor panel Release the line and within the resulting connection dialog establish an Action method on the Touch Up Inside event configured to call a method named saveData Select the ArchiveViewController h file and add an additional NSString property to store a reference to the path to the archive data file import UIKit UIKit h interface ArchiveViewController UIViewController property strong nonatomic IBOutlet UITextField name property strong nonatomic IBOutlet UITextField address property strong nonatomic IBOutlet UITextField phone property strong nonatomic NSString dataFilePath IBAction saveData end Checking for the Existence of the Archive File on Startup Each time the application is launched by the user the code will need to identify whether the archive data file exists from a previous session In the event that it does exist the application will need to read the contents to recreate the original array object from which the archive was created Using this newly recreated array object the array elements will then be extracted and used to populate the name address and phone text fields The traditional location for placing such initialization code is in the viewDidLoad method of the view controller class Within the project window therefore select the ArchiveViewController m file and scroll down the contents of this file until you reach the viewDidLoad method Having located the method modify it as outlined in the following code fragment void viewDidLoad super viewDidLoad NSFileManager filemgr NSString docsDir NSArray dirPaths filemgr NSFileManager defaultManager Get the documents directory dirPaths NSSearchPathForDirectoriesInDomains NSDocumentDirectory NSUserDomainMask YES docsDir dirPaths 0 Build the path to the data file dataFilePath NSString alloc initWithString docsDir stringByAppendingPathComponent data archive Check

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

  • IOS 6 iPad Database Implementation using SQLite - Techotopia
    will be located on the host system in the following folder Users user Library Application Support iPhone Simulator sdk version Applications id Documents Where user is the login name of the user running the iOS Simulator session sdk version is the version of the iOS SDK used to build the application and id is the unique ID of the application Preparing an iPad Application Project for SQLite Integration By default the Xcode environment does not assume that you will be including SQLite in your application When developing SQLite based applications a few additional steps are required to ensure the code will compile when the application is built Firstly the project needs to be configured to include the libsqlite3 dylib dynamic library during the link phase of the build process To achieve this select the target entry in the Xcode project navigator the top entry with the product name to display the summary information Select the Build Phases tab to display the build information Figure 38 1 The Link Binary with Libraries section lists the libraries and frameworks already included in the project To add another library or framework click on the button to display the full list From this list search for and then select the required item in this case libsqlite3 dylib and click Add Secondly the sqlite3 h include file must be imported into any files where references are made to SQLite definitions declarations or functions This file may be imported when needed as follows import sqlite3 h Key SQLite Functions When implementing a database using SQLite it will be necessary to utilize a number of C functions contained within the libsqlite3 dylib library A summary of the most commonly used functions is as follows sqlite3 open Opens specified database file If the database file does not already exist it is created sqlite3 close Closes a previously opened database file sqlite3 prepare v2 Prepares a SQL statement ready for execution sqlite3 step Executes a SQL statement previously prepared by the sqlite3 prepare v2 function sqlite3 column type Returns a data field from the results of a SQL retrieval operation where type is replaced by the data type of the data to be extracted text blob bytes int int16 etc sqlite3 finalize Deletes a previously prepared SQL statement from memory sqlite3 exec Combines the functionality of sqlite3 prepare v2 sqlite3 step and sqlite3 finalize into a single function call This of course represents only a small subset of the complete range of functions available with SQLite A full list can be found at http www sqlite org c3ref funclist html Declaring a SQLite Database Before any tasks can be performed on a database it must first be declared To do so it is necessary to declare a variable that points to an instance of a structure of type sqlite3 the sqlite3 structure is defined in the sqlite3 h include file For example sqlite3 contactDB Declare a pointer to sqlite database structure Opening or Creating a Database Once declared a

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

  • An Example SQLite based iOS 6 iPad Application - Techotopia
    remaining text fields and the label object to properties named address and phone respectively and status Ctrl click on the Save button object and drag the line to the area immediately beneath the newly created outlet in the Assistant Editor panel Release the line and within the resulting connection dialog establish an Action method on the Touch Up Inside event configured to call a method named saveData Repeat this step to create an action connection from the Find button to a method named findContact On completion of these steps the DatabaseViewController h file should read as follows import UIKit UIKit h import sqlite3 h interface DatabaseViewController UIViewController property strong nonatomic IBOutlet UITextField name property strong nonatomic IBOutlet UITextField address property strong nonatomic IBOutlet UITextField phone property strong nonatomic IBOutlet UILabel status IBAction saveData id sender IBAction findContact id sender property strong nonatomic NSString databasePath property nonatomic sqlite3 contactDB end Creating the Database and Table When the application is launched it will need to check whether the database file already exists and if not create both the database file and a table within the database in which to store the contact information entered by the user The code to perform this task can be placed in the viewDidLoad method of our view controller class Select the DatabaseViewController m file scroll down to the viewDidLoad method and modify it as follows void viewDidLoad super viewDidLoad NSString docsDir NSArray dirPaths Get the documents directory dirPaths NSSearchPathForDirectoriesInDomains NSDocumentDirectory NSUserDomainMask YES docsDir dirPaths 0 Build the path to the database file databasePath NSString alloc initWithString docsDir stringByAppendingPathComponent contacts db NSFileManager filemgr NSFileManager defaultManager if filemgr fileExistsAtPath databasePath NO const char dbpath databasePath UTF8String if sqlite3 open dbpath contactDB SQLITE OK char errMsg const char sql stmt CREATE TABLE IF NOT EXISTS CONTACTS ID INTEGER PRIMARY KEY AUTOINCREMENT NAME TEXT ADDRESS TEXT PHONE TEXT if sqlite3 exec contactDB sql stmt NULL NULL errMsg SQLITE OK status text Failed to create table sqlite3 close contactDB else status text Failed to open create database The code in the above method performs the following tasks Identifies the application s Documents directory and constructs a path to the contacts db database file Creates an NSFileManager instance and subsequently uses it to detect if the database file already exists If the file does not yet exist the code converts the path to a UTF 8 string and creates the database via a call to the SQLite sqlite3 open function passing through a reference to the contactDB variable declared previously in the interface file Prepares a SQL statement to create the contacts table in the database Reports the success or otherwise of the operation via the status label Closes the database Implementing the Code to Save Data to the SQLite Database The saving of contact data to the database is the responsibility of the saveData action method This method will need to open the database file extract the text from the three text fields and construct and execute a SQL INSERT statement

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

  • Working with iOS 6 iPad Databases using Core Data - Techotopia
    one to one one to many or many to many Fetched property This provides an alternative to defining relationships Fetched properties allow properties of one data object to be accessed from another data object as though a relationship had been defined between those entities Fetched properties lack the flexibility of relationships and are referred to by Apple s Core Data documentation as weak one way relationships best suited to loosely coupled relationships Fetch request A predefined query that can be referenced to retrieve data objects based on defined predicates For example a fetch request can be configured into an entity to retrieve all contact objects where the name field matches John Smith Persistent Store Coordinator The persistent store coordinator is responsible for coordinating access to multiple persistent object stores As an iPad iOS developer you will never directly interact with the persistence store coordinator and in fact will very rarely need to develop an application that requires more than one persistent object store When multiple stores are required the coordinator presents these stores to the upper layers of the Core Data stack as a single store Persistent Object Store The term persistent object store refers to the underlying storage environment in which data are stored when using Core Data Core Data supports three disk based and one memory based persistent store Disk based options consist of SQLite XML and binary By default the iOS SDK will use SQLite as the persistent store In practice the type of store being used is transparent to you as the developer Regardless of your choice of persistent store your code will make the same calls to the same Core Data APIs to manage the data objects required by your application Defining an Entity Description Entity descriptions may be defined from within the Xcode environment When a new project is created with the option to include Core Data a template file will be created named projectname xcdatamodeld Selecting this file in the Xcode project navigator panel will load the model into the entity editing environment as illustrated in Figure 40 2 Figure 40 2 Create a new entity by clicking on the Add Entity button located in the bottom panel The new entity will appear as a text box in the Entities list where a name may be typed To add attributes to the entity click on the Add Attribute button located in the bottom panel In the Attributes panel name the attribute and specify the type and any other options that are required Repeat the above steps to add more attributes and additional entities The Xcode entity environment also allows relationships to be established between entities Assume for example two entities named Contacts and Sales In order to establish a relationship between the two tables select the Contacts entity and click on the button beneath the Relationships panel In the detail panel name the relationship specify the destination as the Sales entity and any other options that are required for the relationship Once the

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

  • An iOS 6 iPad Core Data Tutorial - Techotopia
    Create Now that we have added the view controller class to the application we need to modify our app delegate to make this the root view controller In the Xcode project navigator select the CoreDataAppDelegate h file and modify it to add a reference to our new view controller import UIKit UIKit h import CoreDataViewController h class CoreDataViewController interface CoreDataAppDelegate UIResponder UIApplicationDelegate property strong nonatomic CoreDataViewController viewController property strong nonatomic UIWindow window property readonly strong nonatomic NSManagedObjectContext managedObjectContext property readonly strong nonatomic NSManagedObjectModel managedObjectModel property readonly strong nonatomic NSPersistentStoreCoordinator persistentStoreCoordinator void saveContext NSURL applicationDocumentsDirectory end With an instance of the view controller declared in the interface file we now need to modify the applicationDidFinishLaunchingWithOptions method located in the CoreDataAppDelegate m implementation file to initialize and allocate the CoreDataViewController instance and assign it as the window view so that it is visible to the user on application launch BOOL application UIApplication application didFinishLaunchingWithOptions NSDictionary launchOptions self window UIWindow alloc initWithFrame UIScreen mainScreen bounds Override point for customization after application launch viewController CoreDataViewController alloc initWithNibName CoreDataViewController bundle nil self window backgroundColor UIColor whiteColor self window setRootViewController viewController self window makeKeyAndVisible return YES Designing the User Interface Select the CoreDataViewController xib file to begin the design work The user interface and corresponding connections used in this tutorial are the same as those in previous data persistence chapters The completed view should once again appear as outlined in Figure 45 3 Figure 45 3 Select the top most text field object in the view canvas display the Assistant Editor panel and verify that the editor is displaying the contents of the CoreDataViewController h file Ctrl click on the text field object again and drag to a position just below the interface line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named name Repeat the above steps to establish outlet connections for the remaining text fields and the label object to properties named address and phone respectively and status Ctrl click on the Save button object and drag the line to the area immediately beneath the newly created outlet in the Assistant Editor panel Release the line and within the resulting connection dialog establish an Action method on the Touch Up Inside event configured to call a method named saveData Repeat this step to create an action connection from the Find button to a method named findContact With the connections established select the CoreDataViewController h file and verify the settings are correct before modifying the file to import the CoreDataAppDelegate h file which will be required by code added to the view controller later in the chapter import UIKit UIKit h import CoreDataAppDelegate h interface CoreDataViewController UIViewController property strong nonatomic IBOutlet UITextField name property strong nonatomic IBOutlet UITextField address property strong nonatomic IBOutlet UITextField phone property strong nonatomic IBOutlet UILabel status IBAction saveData id sender IBAction findContact id sender end Saving Data to the Persistent Store using Core Data When the user touches the Save button

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

  • An Example iOS 6 iPad Touch, Multitouch and Tap Application - Techotopia
    Show Object Library and modifying properties until the view appears as outlined in Figure 47 1 When adding the labels to the right of the view be sure to stretch them so that they reach beyond the center of the view area Figure 47 1 Select label to the right of the Method label display the Assistant Editor panel and verify that the editor is displaying the contents of the TouchViewController h file Ctrl click on the same label object and drag to a position just below the interface line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named methodStatus Repeat the above steps to establish outlet connections for the remaining labels object to properties named touchStatus and tapStatus Enabling Multitouch on the View By default views are configured to respond to only single touches in other words a single finger touching or tapping the screen at any one time For the purposes of this example we plan to detect multiple touches In order to enable this support it is necessary to change an attribute of the view object To achieve this click on the background of the View window display the Attribute Inspector View Utilities Show Attribute Inspector and make sure that the Multiple Touch option is selected in the Interaction section at the bottom of the window Figure 47 2 Implementing the touchesBegan Method When the user touches the screen the touchesBegan method of the first responder is called In order to capture these event types we need to implement this method in our view controller In the Xcode project navigator select the TouchViewController m file and add the touchesBegan method as follows void touchesBegan NSSet touches withEvent UIEvent event NSUInteger touchCount touches count NSUInteger tapCount touches anyObject tapCount methodStatus text touchesBegan touchStatus text NSString stringWithFormat d touches touchCount tapStatus text NSString stringWithFormat d taps tapCount This method obtains a count of the number of touch objects contained in the touches set essentially the number of fingers touching the screen and assigns it to a variable It then gets the tap count from one of the touch objects The code then updates the methodStatus label to indicate that the touchesBegan method has been triggered constructs a string indicating the number of touches and taps detected and displays the information on the touchStatus and tapStatus labels accordingly Implementing the touchesMoved Method When the user moves one or more fingers currently in contact with the surface of the iPad touch screen the touchesMoved method is called repeatedly until the movement ceases In order to capture these events it is necessary to implement the touchesMoved method in our view controller class void touchesMoved NSSet touches withEvent UIEvent event NSUInteger touchCount touches count NSUInteger tapCount touches anyObject tapCount methodStatus text touchesMoved touchStatus text NSString stringWithFormat d touches touchCount tapStatus text NSString stringWithFormat d taps tapCount Once again we report the number of touches and taps detected and indicate to the user that this

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

  • Detecting iOS 6 iPad Touch Screen Gesture Motions - Techotopia
    iPad and name the project and class prefix TouchMotion with Storyboard support and Automatic Reference Counting enabled Designing the Application User Interface The application will display the X and Y coordinates of the touch and update these values in real time as the finger moves across the screen When the finger is lifted from the screen the start and end coordinates of the gesture will then be displayed on two label objects in the user interface Select the MainStoryboard storyboard file and using Interface Builder create a user interface such that it resembles the layout in Figure 48 1 Figure 48 1 Be sure to stretch the labels so that they both extend to cover most of the width of the view Select the top label object in the view canvas display the Assistant Editor panel and verify that the editor is displaying the contents of the TouchMotionViewController h file Ctrl click on the same label object and drag to a position just below the interface line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named xCoord Repeat this step to establish an outlet connection to the second label object named yCoord Next select the TouchMotionViewController h file verify that the outlets are correct then declare a property in which to store coordinates of the start location on the screen import UIKit UIKit h interface TouchMotionViewController UIViewController property strong nonatomic IBOutlet UILabel xCoord property strong nonatomic IBOutlet UILabel yCoord property CGPoint startPoint end Implementing the touchesBegan Method When the user first touches the screen the location coordinates need to be saved in the startPoint instance variable and the coordinates reported to the user This can be achieved by implementing the touchesBegan method in the TouchMotionViewController m file as follows void touchesBegan NSSet touches withEvent UIEvent event UITouch theTouch touches anyObject startPoint theTouch locationInView self view CGFloat x startPoint x CGFloat y startPoint y xCoord text NSString stringWithFormat x f x yCoord text NSString stringWithFormat y f y Implementing the touchesMoved Method When the user s finger moves across the screen the touchesMoved event will be called repeatedly until the motion stops By implementing the touchesMoved method in our view controller therefore we can detect the motion and display the revised coordinates to the user void touchesMoved NSSet touches withEvent UIEvent event UITouch theTouch touches anyObject CGPoint touchLocation theTouch locationInView self view CGFloat x touchLocation x CGFloat y touchLocation y xCoord text NSString stringWithFormat x f x yCoord text NSString stringWithFormat y f y Implementing the touchesEnded Method When the user s finger lifts from the screen the touchesEnded method of the first responder is called The final task therefore is to implement this method in our view controller such that it displays the start and end points of the gesture void touchesEnded NSSet touches withEvent UIEvent event UITouch theTouch touches anyObject CGPoint endPoint theTouch locationInView self view xCoord text NSString stringWithFormat start f f startPoint x startPoint y yCoord text NSString

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



  •