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 Example iOS 7 iPhone Camera Application - Techotopia
    20 points spacing to the corresponding edges of the containing view Figure 75 3 With the constraints configured click on the Add 3 Constraints button Finally with the Image View still selected display the Size Inspector panel View Utilities Show Size Inspector and reduce the Vertical Content Compression Resistance Priority value to 100 This will prevent the image view from growing vertically and obscuring the toolbar when displaying large images Select the image view object in the view canvas display the Assistant Editor panel and verify that the editor is displaying the contents of the CameraViewController h file Ctrl click on the image view 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 imageView With the Assistant Editor visible establish action connections for the two buttons to methods named useCamera and useCameraRoll respectively keeping mind that it may be necessary to click twice on each button to select it since the first click will typically select the toolbar parent object Finally select the CameraViewController h file and modify it further to add import and delegate protocol declarations together with a boolean property declaration that will be required later in the chapter import UIKit UIKit h import MobileCoreServices MobileCoreServices h interface CameraViewController UIViewController UIImagePickerControllerDelegate UINavigationControllerDelegate property BOOL newMedia property strong nonatomic IBOutlet UIImageView imageView IBAction useCamera id sender IBAction useCameraRoll id sender end 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 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 id sender if UIImagePickerController isSourceTypeAvailable UIImagePickerControllerSourceTypeCamera UIImagePickerController imagePicker UIImagePickerController alloc init imagePicker delegate self imagePicker sourceType UIImagePickerControllerSourceTypeCamera imagePicker mediaTypes NSString kUTTypeImage imagePicker allowsEditing NO self presentViewController imagePicker animated YES completion nil newMedia YES end 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 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 id sender if UIImagePickerController isSourceTypeAvailable UIImagePickerControllerSourceTypeSavedPhotosAlbum UIImagePickerController imagePicker UIImagePickerController

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


  • Video Playback from within an iOS 7 Application - Techotopia
    controlStyle property Playback may also be controlled from the application code by implementing the methods defined in the MPMediaPlayback protocol The MPMoviePlayerController class also employs the target action model for notifying the application of events such as the movie starting finishing being paused entering and leaving full screen mode etc Supported Video Formats The MPMoviePlayerController class supports the playback of movies of type mov mp4 mpv and 3gp In terms of compression the class supports H 264 Baseline Profile Level 3 0 and MPEG 4 Part 2 video The iOS Movie Player Example Application The objective of the remainder of this chapter is to create a simple application that will play back a video when a button is pressed The video will be streamed over the internet from a movie file located on a web server Begin by launching Xcode and creating a new iOS application project for either the iPhone or iPad based on the Single View Application template naming the product and class prefix Movie when prompted to do so Designing the User Interface Select the Main storyboard file and display the Object Library View Utilities Show Object Library Drag a single Button instance to the view window and change the text on the button to Play Movie Display the Assistant Editor Ctrl click on the button object and drag the line to the area immediately beneath the interface line 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 playMovie 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 Declaring the MoviePlayer Instance Before proceeding it is imperative that the MediaPlayer MediaPlayer h file be imported to avoid a catalog of unresolved references when the application is compiled A reference to an instance of the MPMoviePlayerController class is also going to be required Select the MovieViewController h file therefore and modify it as follows import UIKit UIKit h import MediaPlayer MediaPlayer h interface MovieViewController UIViewController property strong nonatomic MPMoviePlayerController moviePlayer IBAction playMovie id sender end Implementing the Action Method The next step is to write the code for the action method so that video playback is initiated when the button is touched by the user The stub method for the playMovie action has been created in MovieViewController m and should be modified as follows void playMovie id sender NSURL url NSURL URLWithString http www ebookfrenzy com ios book movie movie mov 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 using the URL of a web based video file This is then used in the creation

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

  • Playing Audio on iOS 7 using AVAudioPlayer - Techotopia
    using the numberOfLoops property Creating the Audio Example Application The remainder of this chapter will work through the creation of a simple iOS 7 application which plays an audio file The user interface of the application will consist of play and stop buttons to control playback and a slider to adjust the playback volume level Begin by launching Xcode and creating a new iPhone or iPad Single View Application named Audio with a matching class prefix when prompted to do so Adding an Audio File to the Project Resources In order to experience audio playback it will be necessary to add an audio file to the project resources For this purpose any supported audio format file will be suitable Having identified a suitable audio file drag and drop it into the Supporting Files category of the project navigator panel of the main Xcode window For the purposes of this tutorial we will be using an MP3 file named Moderato mp3 which can be found in the audiofiles folder of the sample code archive downloadable from the following URL http www ebookfrenzy com web ios7 Having downloaded and unzipped the file locate it in a Finder window and drag and drop it onto the Supporting Files section of the Xcode project navigator panel Designing the User Interface The application user interface is going to comprise two buttons labeled Play and Stop and a slider to allow the volume of playback to be adjusted Select the Main storyboard file display the Object Library View Utilities Show Object Library drag and drop components from the Library onto the View window and modify properties so that the interface appears as illustrated in Figure 77 1 Figure 77 1 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 Select the slider object in the view canvas display the Assistant Editor panel and verify that the editor is displaying the contents of the AudioViewController h file Ctrl click on the slider 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 volumeControl Ctrl click on the Play 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 playAudio Repeat these steps to establish an action on the Stop button to a method named stopAudio Ctrl click on the slider object and drag the line to the area immediately beneath the newly created actions in the Assistant Editor panel Release the line and within the resulting connection dialog establish an Action method on the Value Changed event configured to call a method

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

  • Recording Audio on iOS 7 with AVAudioRecorder - Techotopia
    interface line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named recordButton Repeat these steps to establish outlet connections for the Play and Stop buttons named playButton and stopButton respectively Continuing to use the Assistant Editor establish Action connections from the three buttons to methods named recordAudio playAudio and stopAudio Select the RecordViewController h file and modify it to import AVFoundation AVFoundation h declare adherence to delegate protocols and add properties to store references to AVAudioRecorder and AVAudioPlayer instances import UIKit UIKit h import AVFoundation AVFoundation h interface RecordViewController UIViewController AVAudioRecorderDelegate AVAudioPlayerDelegate property strong nonatomic AVAudioRecorder audioRecorder property strong nonatomic AVAudioPlayer audioPlayer property strong nonatomic IBOutlet UIButton recordButton property strong nonatomic IBOutlet UIButton playButton property strong nonatomic IBOutlet UIButton stopButton IBAction recordAudio id sender IBAction playAudio id sender IBAction stopAudio id sender end Creating the AVAudioRecorder Instance When the application is first launched an instance of the AVAudioRecorder class needs to be created This will be initialized with the URL of a file into which the recorded audio is to be saved Also passed as an argument to the initialization method is an NSDictionary object indicating the settings for the recording such as bit rate sample rate and audio quality A full description of the settings available may be found in the appropriate Apple iOS reference materials 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 As is often the case a good location to initialize the AVAudioRecorder instance is the viewDidLoad method of the view controller located in the RecordViewController m file Select the file in the project navigator locate this method and modify it so that it reads as follows void viewDidLoad super viewDidLoad playButton enabled NO stopButton enabled NO NSArray dirPaths NSString docsDir dirPaths NSSearchPathForDirectoriesInDomains NSDocumentDirectory NSUserDomainMask YES docsDir dirPaths 0 NSString soundFilePath docsDir stringByAppendingPathComponent sound caf NSURL soundFileURL NSURL fileURLWithPath soundFilePath NSDictionary recordSettings NSDictionary dictionaryWithObjectsAndKeys NSNumber numberWithInt AVAudioQualityMin AVEncoderAudioQualityKey NSNumber numberWithInt 16 AVEncoderBitRateKey NSNumber numberWithInt 2 AVNumberOfChannelsKey NSNumber numberWithFloat 44100 0 AVSampleRateKey nil NSError error nil AVAudioSession audioSession AVAudioSession sharedInstance audioSession setCategory AVAudioSessionCategoryPlayAndRecord error nil audioRecorder AVAudioRecorder alloc initWithURL soundFileURL settings recordSettings error error if error NSLog error error localizedDescription else audioRecorder prepareToRecord Since no audio has yet been recorded the above method disables the play and stop buttons It then identifies the application s documents directory and constructs a URL to a file in that location named sound caf An NSDictionary object is then created containing the recording quality settings before an audio session and an instance of the AVAudioRecorder class are created Assuming no errors are encountered the audioRecorder instance is prepared to begin recording when requested to do so by the user Implementing the Action Methods The next step is to implement the action methods connected to the three button objects Select the

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

  • Integrating Twitter and Facebook into iOS 7 Applications - Techotopia
    main screen of the Settings application Options are also provided on the Facebook settings panel to control which applications have access to the Facebook account and to modify or delete the currently configured Facebook account When using the SLRequest class to construct API requests it will be necessary to use the Accounts framework to identify and request permission to use the corresponding social network accounts in an application When using the UIActivityViewController or SLComposeViewController classes however the account handling is performed automatically by the class The remainder of this chapter will focus on the UIActivityViewController and SLComposeViewController classes The SLRequest class will be covered in detail in the chapter entitled iOS 7 Facebook and Twitter Integration using SLRequest Using the UIActivityViewController Class The UIActivityViewController class is instantiated within an application at the point at which a posting is ready to be made to a social network Once the user takes an action to post an update from within an application the screen shown in Figure 79 2 will appear listing the options that are available Figure 79 2 Once a destination social network has been selected the preview sheet for the chosen service Figure 79 3 shows the sheet for a Facebook posting will appear primed with the content of the update to be sent consisting of text and any optional image attachments Having reviewed and optionally modified the post the user may then send the message Figure 79 3 In the event that the user has not yet configured an account for the selected social network in the Settings application a dialog will appear providing the option to either set up an account or cancel the post 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 The assumption is generally made that at the point an instance of UIActivityViewController is created the application will already have gathered together the text and images that are to be included in the post These items need to be placed into an NSArray object and passed to the controller before it is presented to the user The following code excerpt for example instantiates a UIActivityViewController instance primed with text and an image to be included in the post and presents it to the user NSString postText My first Facebook post from iOS 7 UIImage postImage UIImage imageNamed myImage png NSArray activityItems postText postImage UIActivityViewController activityController UIActivityViewController alloc initWithActivityItems activityItems applicationActivities nil self presentViewController activityController animated YES completion nil Using the SLComposeViewController Class In order to use the SLComposeViewController class a number of steps should be performed in sequence Firstly the application may optionally check to verify whether a message can be sent to the specified social network service This essentially equates to checking if a valid social network account has been configured on the device and is achieved using the isAvailableForServiceType class

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

  • An iOS 7 Facebook Integration Tutorial using UIActivityViewController - Techotopia
    then display the editor using View Assistant Editor Show Assistant Editor menu option Alternatively it may also be displayed by selecting the center button the one containing an image of a bow tie and tuxedo of the row of Editor toolbar buttons in the top right hand corner of the main Xcode window Make sure that the SocialAppViewController h file is displayed in the editor before Ctrl clicking on the Text View object in the view and dragging the resulting line to the area immediately beneath the interface directive in the Assistant Editor panel Upon releasing the line the configuration panel will appear Configure the connection as an Outlet named postText and click on the Connect button Repeat the above steps to add an outlet for the Image View object named postImage The application will require three actions One for each of the button objects and one for the background view that will be used to hide the keyboard when the user has finished entering text Ctrl click on the Select Image button and drag the resulting line to a position beneath the new outlets previously declared in the Assistant Editor In the resulting configuration panel change the Connection type to Action and name the method selectImage Repeat this step to add an action for the Post Message button this time naming the action sendPost Once the connections have been established select the SocialAppViewController h file and further modify it to configure the class to act as an image picker delegate and to add some imports that will be required later in the tutorial import UIKit UIKit h import Social Social h import MobileCoreServices MobileCoreServices h interface SocialAppViewController UIViewController UIImagePickerControllerDelegate UINavigationControllerDelegate property strong nonatomic IBOutlet UITextView postText property strong nonatomic IBOutlet UIImageView postImage IBAction selectImage id sender IBAction sendPost id sender end 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 selectImage and Delegate Methods The purpose of the selectImage action method is to provide the user with access to photos on the device and allow one to be selected for inclusion in the Facebook post With these requirements in mind select the SocialAppViewController m file locate the selectImage stub added by the Assistant editor and modify it as follows IBAction selectImage id sender if UIImagePickerController isSourceTypeAvailable UIImagePickerControllerSourceTypeSavedPhotosAlbum UIImagePickerController imagePicker UIImagePickerController alloc init imagePicker delegate self imagePicker sourceType UIImagePickerControllerSourceTypePhotoLibrary imagePicker mediaTypes NSString kUTTypeImage imagePicker allowsEditing NO self presentViewController imagePicker animated YES completion nil Next add the other image picker delegate methods so that the picker is dismissed when the user has made a selection pragma mark pragma mark UIImagePickerControllerDelegate void imagePickerController UIImagePickerController picker didFinishPickingMediaWithInfo NSDictionary info NSString mediaType info UIImagePickerControllerMediaType self dismissViewControllerAnimated YES completion nil if mediaType isEqualToString NSString kUTTypeImage UIImage image info UIImagePickerControllerOriginalImage postImage image image void imagePickerControllerDidCancel UIImagePickerController picker self dismissViewControllerAnimated YES completion nil Hiding

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

  • IOS 7 Facebook and Twitter Integration using SLRequest - Techotopia
    appropriately configured ACAccountType object The following code for example seeks access to the Twitter accounts configured on the device ACAccountStore account ACAccountStore alloc init ACAccountType accountType account accountTypeWithAccountTypeIdentifier ACAccountTypeIdentifierTwitter account requestAccessToAccountsWithType accountType options nil completion BOOL granted NSError error if granted YES Get account and communicate with Twitter API In the event that access is granted an array of Twitter accounts on the device can be obtained via a subsequent call to the accountsWithAccountType method of the account object used for the request The required account may then be extracted from the array of accounts for use in constructing an SLRequest object The following code accesses the array of accounts selects the last account entry and assigns it to twitterAccount ACAccountStore account ACAccountStore alloc init ACAccountType accountType account accountTypeWithAccountTypeIdentifier ACAccountTypeIdentifierTwitter account requestAccessToAccountsWithType accountType options nil completion BOOL granted NSError error if granted YES NSArray arrayOfAccounts account accountsWithAccountType accountType if arrayOfAccounts count 0 ACAccount twitterAccount arrayOfAccounts lastObject The next task is to request an SLRequest object for Twitter access This is achieved via a call to the requestForServiceType class method of the SLRequest class passing through the following values The type of social network service for which the SLRequest will be used in this case SLServiceTypeTwitter The HTTP request method type SLRequestMethodPOST SLRequestMethodGET or SLRequestMethodDELETE The URL required by the social network API for interaction An NSDictionary object containing any parameters required by the social network API to complete the transaction The following code changes request an SLRequest instance configured for sending a Twitter update containing the text My first Twitter post from iOS 7 ACAccountStore account ACAccountStore alloc init ACAccountType accountType account accountTypeWithAccountTypeIdentifier ACAccountTypeIdentifierTwitter account requestAccessToAccountsWithType accountType options nil completion BOOL granted NSError error if granted YES NSArray arrayOfAccounts account accountsWithAccountType accountType if arrayOfAccounts count 0 ACAccount twitterAccount arrayOfAccounts lastObject NSDictionary message status My First Twitter post from iOS 7 NSURL requestURL NSURL URLWithString http api twitter com 1 statuses update json SLRequest postRequest SLRequest requestForServiceType SLServiceTypeTwitter requestMethod SLRequestMethodPOST URL requestURL parameters message 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 Finally the account object needs to be assigned to the SLRequest object and the request posted to the Twitter API ACAccountStore account ACAccountStore alloc init ACAccountType accountType account accountTypeWithAccountTypeIdentifier ACAccountTypeIdentifierTwitter account requestAccessToAccountsWithType accountType options nil completion BOOL granted NSError error if granted YES NSArray arrayOfAccounts account accountsWithAccountType accountType if arrayOfAccounts count 0 ACAccount twitterAccount arrayOfAccounts lastObject NSDictionary message status My First Twitter post from iOS6 NSURL requestURL NSURL URLWithString http api twitter com 1 statuses update json SLRequest postRequest SLRequest requestForServiceType SLServiceTypeTwitter requestMethod SLRequestMethodPOST URL requestURL parameters message postRequest account twitterAccount postRequest performRequestWithHandler NSData responseData NSHTTPURLResponse urlResponse NSError error NSLog Twitter HTTP response i urlResponse statusCode For the purposes of this example the handler for the performRequestWithHandler method simply outputs the HTTP response code for the request

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

  • An iOS 7 Twitter Integration Tutorial using SLRequest - Techotopia
    import Accounts Accounts h import Social Social h interface TwitterAppViewController UIViewController UITableViewDataSource UITableViewDelegate property strong nonatomic IBOutlet UITableView tweetTableView property strong nonatomic NSArray dataSource end Accessing the Twitter API The code to access the Twitter account and extract the posts from the account timeline will reside in a method named getTimeLine located in the TwitterAppViewController m file Select this file and modify it to add the code for this new method void getTimeLine ACAccountStore account ACAccountStore alloc init ACAccountType accountType account accountTypeWithAccountTypeIdentifier ACAccountTypeIdentifierTwitter account requestAccessToAccountsWithType accountType options nil completion BOOL granted NSError error if granted YES NSArray arrayOfAccounts account accountsWithAccountType accountType if arrayOfAccounts count 0 ACAccount twitterAccount arrayOfAccounts lastObject NSURL requestURL NSURL URLWithString https api twitter com 1 1 statuses user timeline json NSDictionary parameters screen name techotopia include rts 0 trim user 1 count 20 SLRequest postRequest SLRequest requestForServiceType SLServiceTypeTwitter requestMethod SLRequestMethodGET URL requestURL parameters parameters postRequest account twitterAccount postRequest performRequestWithHandler NSData responseData NSHTTPURLResponse urlResponse NSError error self dataSource NSJSONSerialization JSONObjectWithData responseData options NSJSONReadingMutableLeaves error error if self dataSource count 0 dispatch async dispatch get main queue self tweetTableView reloadData else Handle failure to get account access Much of the code in this method will be familiar from the previous chapter There are however some notable exceptions Firstly the URL used in the request is intended to return the entries in the time line of the user s Twitter account NSURL requestURL NSURL URLWithString https api twitter com 1 1 statuses user timeline json 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 The URL specified requires additional parameters specifying how much data is to be returned In this case the request is limited to the 20 most recent posts and configured to include the tweet entities NSDictionary parameters screen name techotopia include rts 0 trim user 1 count 20 The SLRequest object is primed to use the SLRequestMethodGET HTTP method This is appropriate since this time we are getting as opposed to posting data SLRequest postRequest SLRequest requestForServiceType SLServiceTypeTwitter requestMethod SLRequestMethodGET URL requestURL parameters parameters Finally the handler code for the postRequest method call now accesses the returned NSData object The NSJSONSerialization class is then used to parse and serialize the data returned and assign it to the dataSource NSArray object The Table View object is then told to reload the data it is displaying causing it to re read the data in the dataSource array and display it to the user An important point to note here is that iOS performs the Twitter API request in a different thread from the main thread of the application Threads are the cornerstone of any multitasking operating system and can be thought of as mini processes running within a main process the purpose of which is to enable at least the appearance of parallel execution paths within applications Since

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



  •