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".
  • An iOS 7 Sprite Kit Particle Emitter Tutorial - Techotopia
    Life Cycle The lifetime property controls the length of time in seconds that a particle lives and is therefore visible before disappearing from view The range property may be used to introduce variance in the lifetime from one particle to the next based on a random time value between 0 and the specified range value Particle Position Range The position properties define the location from which particles are created The X and Y values can be used to declare an area around the center of the node location from which particles will be created randomly Angle The angle at which a newly emitted particle will travel away from the creation point in counterclockwise degrees where a value of 0 degrees equates to rightward movement Random variance in direction can be introduced via the range property Particle Speed The speed property specifies the initial speed of the particles at time of creation The speed can be randomized by specifying a range value Particle Acceleration The acceleration properties control the degree to which a particle accelerates or decelerates after emission in terms of both X and Y directions Particle Scale The size of the particles can be configured to change using the scale properties These settings cause the particles to grow or shrink over the course of their lifetimes Random resizing behavior can be implemented by specifying a range value The speed setting controls the speed with which the size changes take place Particle Rotation The rotation properties control the speed and amount of rotation applied to the particles after creation Values are specified in degrees with positive and negative values correlating to clockwise and counter clockwise rotation respectively The speed of rotation may be specified in degrees per second Particle Color The particles created by an emitter can be configured to transition through a range of colors during a lifetime To add a new color in the lifecycle timeline click on the color ramp at the location where the color is to change and select a new color Change an existing color by double clicking on the marker to display the color selection dialog Figure 59 3 for example shows a color ramp with three color transitions specified Figure 59 3 To remove a color from the color ramp click and drag it downward out of the editor panel The color blend settings control the amount by which the colors in the particle s texture blend with the prevailing color in the color ramp at any given time during the life of the particle The greater the Factor property the greater the colors blend with 0 indicating no blending The blending factor can be randomized by specifying a range and the speed at which the blend is performed by adjusting the speed property Particle Blend Mode The Blend Mode property governs the way in which particles blend with other images colors and graphics in Sprite Kit game scenes Options available are as follows Alpha Blends transparent pixels in the particle with

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


  • Integrating iAds into an iOS 7 App - Techotopia
    300x250 pixel rectangle This ad format is designed to be used within the content of a view and is only available for iPad based iOS applications Medium rectangle ads are represented by instances of the AdBannerView class which must be assigned a delegate that conforms to the ADBannerViewDelegate protocol These delegate methods are called to notify the application of whether or not an ad is ready to be displayed It is the responsibility of these methods to position display and hide the ad within the view as needed For as long as the banner is visible and the device has internet connectivity the banner will cycle through different ads The following code for example creates a medium rectangle ad instance and assigned the current class as the delegate rectangleAdView ADBannerView alloc initWithAdType ADAdTypeMediumRectangle rectangleAdView delegate self When an ad is ready to be displayed the bannerViewDidLoadAd method of the delegate will be called the responsibility of which is to display the ad within the current view For example void bannerViewDidLoadAd ADBannerView banner self view addSubview banner self view layoutIfNeeded Note that the above code does not attempt to position the ad rectangle In a real world application code will need to be added so that the ad appears in the appropriate location on the view The rectangle ad will rotate through different ads as long as inventory is available In the event that an ad is not available or the device loses connectivity the didFailToReceiveAdWithError delegate method will be called so that the advert can be removed from the view until another ad is available to be displayed void bannerView ADBannerView banner didFailToReceiveAdWithError NSError error banner removeFromSuperview self view layoutIfNeeded As with the banner ad format a full screen advertisement will be displayed in the event that the user taps on the rectangle ad Once again the viewWillDisappear and viewWillAppear delegate methods may be used to pause and resume the application if appropriate Pre Roll Video Ads For applications that make use of the iOS MediaPlayer framework to play videos this feature allows advertisement videos to be played before the actual video is played to the user This simply involves calling the playPrerollAdWithCompletionHandler method of the media player instance A completion handler is then called so that the playback of the actual video can be initiated when the ad has finished running For example NSURL url NSURL URLWithString http www ebookfrenzy com ios book movie movie mov moviePlayer MPMoviePlayerController alloc initWithContentURL url self view addSubview moviePlayer view moviePlayer setFullscreen YES animated YES moviePlayer playPrerollAdWithCompletionHandler NSError error moviePlayer play As with the interstitial ad format Apple recommends preparing the application for pre roll video ads at application launch time BOOL application UIApplication application didFinishLaunchingWithOptions NSDictionary launchOptions MPMoviePlayerController preparePrerollAds return YES Creating an Example iAds Application In the remainder of this chapter we will work step by step through the creation of a simple iOS 7 application that includes banner interstitial and rectangle based iAd advertisements Begin this tutorial by launching Xcode

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

  • IOS 7 Multitasking, Background Transfer Service and Fetching - Techotopia
    Xcode In situations where an application is required to enter background mode a configuration setting is required in the application s Info plist file The simplest way to make this configuration change is to select the application target at the top of the project navigator panel select the Capabilities tab and switch the Background Modes option from Off to On as illustrated in Figure 61 1 Figure 61 1 Once selected the appropriate setting will be added to the application s Info plist file to enable multitasking support eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Supported Forms of Background Execution So far we have looked primarily at the types of applications for which a suspended background state is acceptable to the user Apple however recognizes nine categories in which application suspension would be detrimental to the user experience these being audio location updates voice over IP VOIP Newsstand updates external and Bluetooth accessory communication background fetch and remote notifications The background execution modes supported by an application are configured in the application s Info plist file using the UIBackgroundModes key The value for the key is actually an array allowing an application to register for more than one background execution mode To select the background modes simply enable the checkbox next to the required modes within the Background Modes section of the project Capabilities panel as outlined in Figure 61 1 above An Overview of Background Fetch Background fetch is a new feature introduced with the iOS 7 SDK that provides a way for an application to be woken up in the background to perform content updates A news application for example might benefit from being given opportunities to download new articles in the background so that the next time the user launches the application it is already populated with the latest news headlines and articles The frequency of background fetch operations can be configured by the application by specifying a time interval or left at the discretion of the operating system When the background fetch schedule is left at the discretion of iOS the operating system will learn the user s pattern of application use and schedule fetch operations so that they occur before those times If iOS notices for example that the application is launched at lunch time each weekday fetch opportunities will be provided for the application prior to that time Background fetch must first be enabled in the background modes settings for the application via the Capabilities panel previously discussed Once enabled the background fetch interval must be set By default this is set to UIApplicationBackgroundFetchIntervalNever which will result in no fetch operations being scheduled To let iOS calculate optimal fetch operations the application s setMinimumBackgroundFetchInterval method may be called within the application delegate as follows BOOL application UIApplication application didFinishLaunchingWithOptions NSDictionary launchOptions

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

  • An iOS 7 Background Transfer Service Tutorial - Techotopia
    begin to implement the functionality in the view controller class First edit the file and import the App Delegate interface file access to the app delegate instance will be needed later to access the reference to the completion handler and declare the URL to the image file that is to be downloaded import BackgroundTransferViewController h import BackgroundTransferAppDelegate h static NSString DownloadURLString http www ebookfrenzy com code LargeImage jpg interface BackgroundTransferViewController end implementation BackgroundTransferViewController end Next edit the viewDidLoad method in the BackgroundTransferViewController m file to begin the initialization process void viewDidLoad super viewDidLoad NSURLSessionConfiguration configuration NSURLSessionConfiguration backgroundSessionConfiguration com ebookfrenzy transfer configuration allowsCellularAccess YES session NSURLSession sessionWithConfiguration configuration delegate self delegateQueue nil NSURL downloadURL NSURL URLWithString DownloadURLString NSURLRequest request NSURLRequest requestWithURL downloadURL downloadTask self session downloadTaskWithRequest request downloadTask resume The above code begins by creating a new NSURLSessionConfiguration instance configured to perform a background transfer and specifying a unique identifier for the session in this case the package name of the application NSURLSessionConfiguration configuration NSURLSessionConfiguration backgroundSessionConfiguration com ebookfrenzy transfer configuration allowsCellularAccess YES By calling the backgroundSessionConfiguration method in the above code we are indicating that the session is required to perform file transfer related tasks An option is also set to allow the transfer to use the cellular connection on the device if WiFi is not available For large transfers this should be set to NO or the user given the opportunity to configure this setting to avoid incurring additional costs on their cellular data plan An NSURLSession instance is then created using the configuration object and designating the current class as the delegate for the session session NSURLSession sessionWithConfiguration configuration delegate self delegateQueue nil Next an NSURL object is created containing the URL of the image file to be downloaded and an NSURLRequest object initialized with this URL NSURL downloadURL NSURL URLWithString DownloadURLString NSURLRequest request NSURLRequest requestWithURL downloadURL Finally the download task request is created and resumed tasks do not start at the point of creation and will not run until the resume method is called downloadTask self session downloadTaskWithRequest request downloadTask resume All that remains is to implement the delegate methods eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Implementing the Session Delegate Methods During the course of the background transfer process a variety of methods on the delegate class will be called depending on the status of the transfer Perhaps the most important is the method that gets called when the download is complete For the purposes of this example this method will copy the image file to the application s Documents folder and display it on the image view Remaining within the BackgroundTransferViewController m file implement this method as follows void URLSession NSURLSession session downloadTask NSURLSessionDownloadTask downloadTask didFinishDownloadingToURL NSURL downloadURL NSLog didFinishDownloadToURL Copying image file NSFileManager fileManager NSFileManager defaultManager NSArray URLs fileManager URLsForDirectory NSDocumentDirectory inDomains

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

  • Scheduling iOS 7 Local Notifications - Techotopia
    iPhone device will still vibrate For the purposes of this exercise we will use a public domain sound clip file named bell tree mp3 which can be found in the audiofiles folder of the sample code archive which may be downloaded using the following URL http www ebookfrenzy com web ios7 Once downloaded drag this file and drop it onto the Supporting Files category located in the Xcode project navigator panel and click the Finish button in the resulting panel The audio file should now be included in the list of resources for the project ready to be accessed by the application code Locating the Application Delegate Method The goal of this exercise is to configure a local notification to be triggered 10 seconds after our application enters the background for additional information on background and suspended applications refer to iOS 7 Multitasking Background Transfer Service and Fetching When an application is placed in the background the application delegate s applicationDidEnterBackground method is triggered It is within this method therefore that the code to schedule the local notification must be placed In the case of this example a template method can be found in the LocalNotifyAppDelegate m file Within the main Xcode project navigator panel select this file and scroll down until the method comes into view void applicationDidEnterBackground UIApplication application Use this method to release shared resources save user data invalidate timers and store enough application state information to restore your application to its current state in case it is terminated later If your application supports background execution called instead of applicationWillTerminate when the user quits eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Scheduling the Local Notification Local notifications require the use of the UILocalNotification class combined with an NSDate object configured with the date and time that the notification is to be triggered Properties may also be set to specify the text to be displayed to the user an optional repeat interval and a message to be displayed to the user in the alert box With these requirements in mind the following code creates an NSDate object based on the current date and time plus 10 seconds This date object is then used to schedule a notification with no repeats a text message and the sound from the audio file void applicationDidEnterBackground UIApplication application NSDate alertTime NSDate date dateByAddingTimeInterval 10 UIApplication app UIApplication sharedApplication UILocalNotification notifyAlarm UILocalNotification alloc init if notifyAlarm notifyAlarm fireDate alertTime notifyAlarm timeZone NSTimeZone defaultTimeZone notifyAlarm repeatInterval 0 notifyAlarm soundName bell tree mp3 notifyAlarm alertBody Staff meeting in 30 minutes app scheduleLocalNotification notifyAlarm Testing the Application To test the application click on the Run tool bar button located in the Xcode project window After compiling and linking the application it will load and run Once the application has loaded press the device

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

  • An Overview of iOS 7 Application State Preservation and Restoration - Techotopia
    the case of storyboards the restoration ID can be set to use the storyboard ID if one has already been assigned Figure 64 1 When assigning restoration IDs in Interface Builder it is important to distinguish between views and view controllers Clicking on the white background of a view in a storyboard for example will select the UIView object not the view controller Clicking on the status bar containing the battery life indicator will on the other hand select the view controller As a general rule wherever possible state preservation should be implemented by saving and restoring the state of the view controller which in turn will be responsible for restoring the state of any child view objects Directly saving and restoring the state of individual view objects in a user interface layout should only be performed when preservation requirements cannot be met using the view controller state Default Preservation Features of UIKit Once state preservation has been enabled and restoration identifiers assigned appropriately it is worth being aware that UIKit will preserve certain state information by default and without the need to write any additional code By default the following state information is saved and restored automatically for view controllers Currently presented view controller Currently selected tab State of navigation stacks In the case of views the following is preserved by default Current scroll position Currently selected cell in a table view Current state of an image view zoom pan etc Web history including scroll position and zoom level Additional state preservation will as will be outlined in the remainder of this chapter require some coding eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Saving and Restoring Additional State Information So far we have ascertained that UIKit will store information about which view controllers and views are to be saved based on whether or not those objects have a restoration ID In many cases each object will have additional information that it needs to save in order to restore the application exactly as the user left it This might for example relate to a specific item the user has selected or some text that has been entered into a Text View but not yet been committed to the application s data model Fortunately UIKit has a way to handle this Once UIKit discovers for example that the state of a specific view controller is to be saved it will check to see if a method named encodeRestorableStateWithCoder has been implemented in that object s class If the method has been implemented UIKit will call that method passing through a reference to an NSCoder object It is then the responsibility of that method to store any additional state data that needs to be preserved into that NSCoder object before returning UIKit will then save that NSCoder object along

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

  • An iOS 7 State Preservation and Restoration Tutorial - Techotopia
    a new outlet connection named myTextView Close the Assistant Editor Build and run the application and once running select the second tab and then select and enter some text into the Text View object Place the application into the background and stop the application using the Xcode Stop button Click on run to launch the application again Whilst the selection of the second tab has been preserved the text entered into the Text View has been lost In order to preserve the text entered by the user it will be necessary to implement the encodeRestorableStateWithCoder and decodeRestorableStateWithCoder methods in the parent view controller of the Text View in this case StateAppSecondViewController Figure 65 2 Select the StateAppSecondViewController m file and add the encoding methods as follows void encodeRestorableStateWithCoder NSCoder coder coder encodeObject myTextView text forKey UnsavedText super encodeRestorableStateWithCoder coder This code is actually very straightforward The method is called by UIKit while the state of the view controller is being saved and is passed an NSCoder object The encodeObject method of the coder methods exist for other types of data as documented in Apple documentation for the NSCoder class is then used to encode the text that is currently held in the myTextView object using a key that will be used to decode the data later The superclass method is then called and the method returns The corresponding decode method also needs to be added void decodeRestorableStateWithCoder NSCoder coder myTextView text coder decodeObjectForKey UnsavedText super decodeRestorableStateWithCoder coder This method simply does the reverse of the encode method It is called by UIKit during the view controller restoration process and passed the NSCoder object containing the saved data The method decodes the text using the previously assigned key and assigns it to the Text View Compile and run the application once again enter some text into the Text View object Place the application into the background before stopping and restarting the application The previously entered text should now be restored and any work entered by the user but not saved has not been lost between application invocations a key objective of iOS state preservation Adding a Navigation Controller to the Storyboard Up until this point in the tutorial all view controllers have resided within a storyboard file As such UIKit has been able to implicitly find and load the controllers at run time The tutorial has so far therefore failed to demonstrate the use of a restoration class to restore a view controller that was created in code as opposed to being stored in a storyboard file The remainder of this chapter will focus on just such a scenario Within the storyboard select the Second view controller and insert a navigation controller using the Editor Embed In Navigation Controller menu option Once added the storyboard should match that illustrated in Figure 65 3 Figure 65 3 Select the new navigation controller in the storyboard canvas display the Identity Inspector and set the restoration ID to navController1 Next select the Second view

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

  • Integrating Maps into iOS 7 Applications using MKMapItem - Techotopia
    suggests involves the translation of geographical coordinates into a human readable address string Consider for example the following code CLGeocoder geocoder CLGeocoder alloc init CLLocation newLocation CLLocation alloc initWithLatitude 40 74835 longitude 73 984911 geocoder reverseGeocodeLocation newLocation completionHandler NSArray placemarks NSError error if error NSLog Geocode failed with error error return if placemarks placemarks count 0 CLPlacemark placemark placemarks 0 NSDictionary addressDictionary placemark addressDictionary NSString address addressDictionary objectForKey NSString kABPersonAddressStreetKey NSString city addressDictionary objectForKey NSString kABPersonAddressCityKey NSString state addressDictionary objectForKey NSString kABPersonAddressStateKey NSString zip addressDictionary objectForKey NSString kABPersonAddressZIPKey NSLog address city state zip In this case a CLLocation object is initialized with longitude and latitude coordinates and then passed through to the reverseGeocodeLocation method of a CLGeocoder object The method passes through to the completion handler an array of matching addresses in the form of CLPlacemark objects Each object contains an NSDictionary object which in turn contains the address information for the matching location Once again the code assumes a single match is contained in the array and uses the dictionary keys to access and display the address city state zip and country values The address dictionary keys follow the standard defined in the Address Property section of the iOS SDK Address Book Person reference When executed the above code results in output which reads 338 5th Avenue New York New York 10001 United States It should be noted that the geocoding is not actually performed on the iOS device but rather on a server to which the device connects when a translation is required and the results subsequently returned when the translation is complete As such geocoding can only take place when the device has an active internet connection Creating MKPlacemark Instances Each location that is to be represented when a map is displayed using the MKMapItem class must be represented by an MKPlacemark object When MKPlacemark objects are created they must be initialized with the geographical coordinates of the location together with an NSDictionary object containing the address property information Continuing the example for the Empire State Building in New York an MKPlacemark object would be created as follows CLLocationCoordinate2D coords CLLocationCoordinate2DMake 40 74835 73 984911 NSDictionary address NSString kABPersonAddressStreetKey 350 5th Avenue NSString kABPersonAddressCityKey New York NSString kABPersonAddressStateKey NY NSString kABPersonAddressZIPKey 10118 NSString kABPersonAddressCountryCodeKey US MKPlacemark place MKPlacemark alloc initWithCoordinate coords addressDictionary address Whilst it is possible to initialize an MKPlacemark object passing through a nil value for the address dictionary this will result in the map appearing albeit with the correct location marked but it will be tagged as Unknown instead of listing the address The coordinates are however mandatory when creating an MKPlacemark object In the event that the application knows the text address but not the coordinates of a location geocoding will need to be used to obtain the coordinates prior to creating the MKPlacemark instance eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App

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



  •