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 9 Today Extension Widget Tutorial - Techotopia
    from the view leaving a clean canvas on which to work By default the template has configured the widget view with a height suitable to accommodate a single label In order to fit two labels onto the widget this height property will need to be increased Click on the gray background of the widget to select the view and display the Size Inspector Within the inspector panel change the Height property from 37 to 50 as shown in Figure 85 7 Figure 85 7 With the height increased drag and drop two Label views from the object palette onto the view canvas stretch the labels to fill approximately half of the width of the widget view and use the Attributes Inspector panel to change the foreground colors of the labels to Light Text Color so that the layout resembles that of Figure 85 8 Figure 85 8 If the extension were to be launched on a device or simulator at this point the labels would not be visible The reason for this is that the Today view relies on Auto Layout settings within the widget layout or specific preferred content size settings in the view controller code to decide on the size at which the widget should appear Since no Auto Layout constraints have been configured and no code has been added to set the preferred content size the widget content would appear at zero height Select the uppermost Label and display the Auto Layout Pin menu Figure 85 9 Enable the Spacing to nearest neighbor constraints on the top and left edges of the label by enabling the red constraint bars and using the current values and with the Constrain to margins option disabled Figure 85 9 Drop down the menu on the Width constraint setting and select the Use current canvas value option Once the spacing and width constraints have been set click on the Add 3 Constraints button to implement the changes Select the bottom Label view and repeat the above steps this time setting spacing constraints on the left top and bottom edges of the view once again using the current spacing values Run the extension and verify that the widget layout appears correctly within the Today view returning to the storyboard file if necessary to make adjustments to the layout Once the layout work is complete display the Assistant Editor panel and make sure that it is showing the source code contained in the TodayViewController swift file Ctrl click on the upper Label view and drag the resulting line to a position beneath the class declaration line in the Assistance Editor panel Release the line and in the resulting connection dialog establish an outlet connection named latitudeLabel Repeat this sequence of steps for the bottom label this time creating an outlet named longitudeLabel Setting the Preferred Content Size in Code Although not necessary in this particular instance since Auto Layout is being used to influence the height of the widget it is worth noting that the height of a widget can be set in code using the setPreferredContentSize method of the extension view controller instance For example the following code changes the height of the widget to 200 before it is displayed to the user override func viewWillAppear animated Bool var currentSize CGSize self preferredContentSize currentSize height 200 0 self preferredContentSize currentSize This technique is particularly useful when it is necessary to dynamically change the size of a widget at runtime A widget might for example display some initial information to the user and provide a More button to display more detailed information In this scenario the More button would simply change the preferred content size to make additional views visible Modifying the Widget View Controller The view controller class for the Today extension widget now needs to be implemented such that it obtains the user s current location and updates the labels in the widget accordingly Select and edit the TodayViewController swift file to import the CoreLocation Framework declare an optional variable in which to store the current location and to create and initialize a location manager instance Note also that the TodayViewController class declaration has been modified to indicate that it now implements the CLLocationManagerDelegate protocol import UIKit import NotificationCenter import CoreLocation class TodayViewController UIViewController NCWidgetProviding CLLocationManagerDelegate IBOutlet weak var latitudeLabel UILabel IBOutlet weak var longitudeLabel UILabel var locationManager CLLocationManager CLLocationManager var currentLocation CLLocation override func viewDidLoad super viewDidLoad locationManager desiredAccuracy kCLLocationAccuracyBest locationManager delegate self locationManager requestLocation eBookFrenzy com Purchase the full edition of this iOS 9 App Development Essentials 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 To meet the conformance requirements of the CLLocationManagerDelegate protocol and in order to be able to receive location update notifications the location manager s didUpdateLocations delegate method now needs to be implemented along with the The code within this method will extract the latest location information and assign it to the previously declared currentLocation optional variable func locationManager manager CLLocationManager didUpdateLocations locations CLLocation currentLocation locations 0 func locationManager manager CLLocationManager didFailWithError error NSError print error description Next a convenience function needs to be written to update the labels with the latest location data func performWidgetUpdate if currentLocation nil let latitudeText String format Lat 4f currentLocation coordinate latitude let longitudeText String format Lon 4f currentLocation coordinate longitude latitudeLabel text latitudeText longitudeLabel text longitudeText This function verifies that the currentLocation optional variable contains a value and if so constructs String objects containing the current longitude and latitude values before displaying them on the corresponding widget labels The last modification to the widget view controller is to ensure that the performWidgetUpdate function is called at the appropriate times so that the user sees the latest location information each time the widget is displayed in the Today view To make sure the function is called prior to the widget being displayed the viewWillAppear method of the view controller needs to be overridden

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


  • Creating an iOS 9 Photo Editing Extension - Techotopia
    it is displaying the source code for the PhotoEditingViewController swift file Select the Bar Button Item displaying the Sepia text note that it may be necessary to click twice since the first click will select the parent Toolbar view With the item selected Ctrl click on the item and drag the resulting line to a position immediately beneath the end of the implementation of the viewDidLoad method in the Assistant Editor panel Release the line and in the connection dialog establish an Action named sepiaSelected Repeat these steps for the Mono and Invert Bar Button Items naming the Actions monoSelected and invertSelected respectively Finally Ctrl click on the Image View and drag the resulting line to a position beneath the class PhotoEditingViewController declaration Release the line and establish an Outlet for the Image View named imageView eBookFrenzy com Purchase the full edition of this iOS 9 App Development Essentials 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 PHContentEditingController Protocol When Xcode created the template for the Photo Editing extension it created a View Controller class named PhotoEditingViewController and declared it as implementing the PHContentEditingController protocol It also generated stub methods for each of the methods that must be implemented in order for the class to conform with the protocol The remainder of implementing a Photo Editing extension primarily consists of writing the code for these methods to implement the required editing behavior One of the first methods that will need to be implemented relates to the issue of adjustment data Photo Extensions and Adjustment Data When a Photo Extension is selected by the user a method named canHandleAdjustmentData is called on the view controller class of the extension The method must return a true or false value depending on whether or not the extension supports adjustment data If an extension supports adjustment data it is passed a copy of the original image or video together with a set of data outlining any earlier modifications made to the media during previous editing sessions The extension then re applies those changes to the file or video to get it back to the point where it was at the end of the last editing session The advantage of this approach is that the extension is able to offer the user the ability to undo any previous editing operations performed within previous sessions using the extension When editing is completed the extension returns the modified image or video file together with any new adjustment data reflecting edits that were performed during the current session If an image editing extension indicates that it does not support adjustment data it is passed a copy of the modified image as it appeared at the end of the last editing session This enables the user to perform additional editing tasks but does not allow previous edits to be undone In the case of video editing extensions that do not support adjustment data the extension will be passed the original video and previous edits will be lost Clearly therefore supporting adjustment data is an important requirement for video editing Whilst the example contained within this tutorial will store and return adjustment data to the Photos app allowing for future improvements to the extension it will not handle incoming adjustment data Within the PhotoEditingViewController swift file therefore locate and review the canHandleAdjustmentData method and verify that it is configured to return a false value func canHandleAdjustmentData adjustmentData PHAdjustmentData Bool return false Receiving the Content The next method that will be called on the extension View Controller class is startContentEditingWithInput This method is passed as arguments a PHContentEditingInput object and a placeholder image For images this object contains a compressed version of the image suitable for displaying to the user a URL referencing the location of the full size image information about the orientation of the image and in the case of extensions with adjustment data support a set of adjustment data from previous edits As previously discussed image extensions with adjustment data support implemented are passed the original image and a set of adjustments to be made to reach parity with the latest state of editing Since it can take time to render these changes the placeholder argument contains a snapshot of the image as it currently appears This can be displayed to the user while the adjustment data is applied and the image rendered in the background For this example the startContentEditingWithInput method will be implemented as follows import UIKit import Photos import PhotosUI class PhotoEditingViewController UIViewController PHContentEditingController IBOutlet weak var imageView UIImageView var input PHContentEditingInput var displayedImage UIImage var imageOrientation Int32 func startContentEditingWithInput contentEditingInput PHContentEditingInput placeholderImage UIImage input contentEditingInput if input nil displayedImage input displaySizeImage imageOrientation input fullSizeImageOrientation imageView image displayedImage The above changes declare two optional variables to contain a reference to the display sized image and the image orientation The code in the method then assigns the display sized image from the PHContentEditingInput object passed to the method to the displayedImage variable and also stores the orientation setting in the imageOrientation variable Finally the display sized image is displayed on the Image View in the user interface so that it is visible to the user Compile and run the extension selecting the Photos app as the host application and verify that the extension displays a copy of the image in the Image View of the extension View Controller Implementing the Filter Actions The actions connected to the Bar Button Items will change the image by applying Core Image sepia monochrome and invert filters Until the user commits the edits made in the extension any filtering will be performed only on the display sized image to avoid the rendering delays that are likely to be incurred working on the full sized image Having performed the filter the modified image will be displayed on the image view instance Remaining within the PhotoEditingViewController swift file implement the three action methods as

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

  • Creating an iOS 9 Action Extension - Techotopia
    host app when the extension is launched All extension view controllers have an associated extension context in the form of an instance of the NSExtensionContext class A reference to the extension context can be accessed via the extensionContext property of the view controller The extension context includes a property named inputItems in the form of an array containing objects which provide access to the content from the host app The input items are in turn contained within one or more NSExtensionItem objects Within the ActionViewController swift file locate the viewDidLoad method remove the template code added by Xcode and modify the method to obtain a reference to the first input item object override func viewDidLoad super viewDidLoad let textItem self extensionContext inputItems 0 as NSExtensionItem Each NSExtensionItem object contains an array of attachment objects These attachment objects are of type NSItemProvider and provide access to the data held by the host app Once a reference to an attachment has been obtained the hasItemConformingToTypeIdentifier method of the object can be called to verify that the host application has data of the type supported by the extension In the case of this example the extension supports text based content so the kUTTypeText uniform type identifier UTI is used to perform this test override func viewDidLoad super viewDidLoad let textItem self extensionContext inputItems 0 as NSExtensionItem let textItemProvider textItem attachments 0 as NSItemProvider if textItemProvider hasItemConformingToTypeIdentifier kUTTypeText as String Assuming that the host app has data of the required type it can be loaded into the extension via a call to the loadItemForTypeIdentifier method of the attachment provider object once again passing through as an argument the UTI content type supported by the extension The loading of the data from the host app is performed asynchronously so a completion handler must be specified which will be called when the data loading process is complete override func viewDidLoad super viewDidLoad let textItem self extensionContext inputItems 0 as NSExtensionItem let textItemProvider textItem attachments 0 as NSItemProvider if textItemProvider hasItemConformingToTypeIdentifier kUTTypeText as String textItemProvider loadItemForTypeIdentifier kUTTypeText as String options nil completionHandler handleCompletion eBookFrenzy com Purchase the full edition of this iOS 9 App Development Essentials 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 When the above code is executed the data associated with the attachment will be loaded from the host app and the specified completion handler in this case a method named handleCompletion will be called Clearly the next step is to implement this completion handler Remaining within the ActionViewController swift file declare an optional variable named convertString and implement this handler so that it reads as follows import UIKit import MobileCoreServices class ActionViewController UIViewController IBOutlet weak var myTextView UITextView var convertedString String func handleCompletion string NSSecureCoding error NSError convertedString string as String if convertedString nil convertedString convertedString uppercaseString dispatch async dispatch get main queue self myTextView text self convertedString The first parameter to the handler method is

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

  • Receiving Data from an iOS 9 Action Extension - Techotopia
    errors this framework must be imported into the ViewController swift file as follows import UIKit import MobileCoreServices class ViewController UIViewController eBookFrenzy com Purchase the full edition of this iOS 9 App Development Essentials 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 Adding a Share Button to the Application In order to be able to access the Change it Up Action extension from within this host application it will be necessary to implement a Share button As the user interface currently stands the toolbar contains a single button item displaying text which reads Item To change this to a Share button select it in the storyboard layout keeping in mind that it may be necessary to click on it twice since the first click typically selects the parent toolbar rather than the button item With the button selected display the Attributes Inspector and change the System Item menu from Custom to Action Figure 88 2 Once the change has been made the button item should now have the standard appearance of an iOS Share button as shown in Figure 88 3 Figure 88 3 Now that the button looks like a Share button some code now needs to be added to display the activity view controller when it is tapped by the user With the Assistant Editor displayed Ctrl click on the button and drag the resulting line to a suitable location within the ViewController swift file Release the line and create an Action outlet named showActionView Once created implement the code in this method so that it reads as follows IBAction func showActionView sender AnyObject let activityViewController UIActivityViewController activityItems myTextView text applicationActivities nil self presentViewController activityViewController animated true completion nil activityViewController completionWithItemsHandler myHandler The code within the method creates a new UIActivityViewController instance initialized with the content of the Text View in the user interface The activity view controller is then displayed to the user Finally a method is assigned to act as the completion handler to be called when the Action extension returns control to the application For now this can be implemented as a stub method as follows func myHandler activityType String completed Bool returnedItems AnyObject error NSError eBookFrenzy com Purchase the full edition of this iOS 9 App Development Essentials 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 Compile and run the application and tap the Share button to test that the activity view controller appears Select the Change it Up extension and verify that it displays the text extracted from the Text View Finally tap the Done button to return to the host app noting that the original text content has not yet been converted to uppercase This functionality now needs to be implemented within the completion handler method Receiving Data from an Extension When the user exits from an Action extension

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

  • Accessing the iOS 9 Camera and Photo Library - Techotopia
    instance and configures it for camera use with image support and editing disabled before displaying the controller let imagePicker UIImagePickerController imagePicker delegate self imagePicker sourceType UIImagePickerControllerSourceType PhotoLibrary imagePicker mediaTypes kUTTypeImage as String imagePicker allowsEditing false self presentViewController imagePicker animated true completion nil 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 eBookFrenzy com Purchase the full edition of this iOS 9 App Development Essentials 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 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 func imagePickerController picker UIImagePickerController didFinishPickingMediaWithInfo info NSObject AnyObject Code here to work with media self dismissViewControllerAnimated true completion nil func imagePickerControllerDidCancel picker UIImagePickerController self dismissViewControllerAnimated true completion nil 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 let mediaType info UIImagePickerControllerMediaType as NSString if mediaType isEqualToString kUTTypeImage as String Media is an image else if mediaType isEqualToString kUTTypeMovie as String Media is a video The original unedited image selected or photographed by the user may be obtained from the info dictionary as follows let image info UIImagePickerControllerOriginalImage as UIImage Assuming that editing was enabled on the image picker controller object the edited version of the image may be accessed via the UImagePickerControllerEditedImage dictionary key let image info UIImagePickerControllerEditedImage as UIImage If the media is a video the URL of the recorded media may be accessed as follows let url info 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 AVPlayer and AVPlayerViewController classes as outlined in the chapter entitled iOS 9 Video Playback using AVPlayer and AVPlayerViewController eBookFrenzy com Purchase the full edition of this iOS 9 App Development Essentials book in eBook 12 99 or

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

  • An Example iOS 9 Camera Application - Techotopia
    to nearest neighbor constraints on all four sides of the view this time with the Constrain to margins option enabled Finally with the Image View still selected display the Attributes Inspector panel and change the Mode attribute to Aspect Fit Select the image view object in the view canvas display the Assistant Editor panel Ctrl click on the image view object and drag to a position just below the class declaration line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named imageView With the Assistant Editor still 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 Close the Assistant Editor select the ViewController swift 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 import MobileCoreServices class ViewController UIViewController UIImagePickerControllerDelegate UINavigationControllerDelegate IBOutlet weak var imageView UIImageView var newMedia Bool 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 true 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 IBAction func useCamera sender AnyObject if UIImagePickerController isSourceTypeAvailable UIImagePickerControllerSourceType Camera let imagePicker UIImagePickerController imagePicker delegate self imagePicker sourceType UIImagePickerControllerSourceType Camera imagePicker mediaTypes kUTTypeImage as String imagePicker allowsEditing false self presentViewController imagePicker animated true completion nil newMedia true eBookFrenzy com Purchase the full edition of this iOS 9 App Development Essentials 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 UIImagePickerControllerSourceType PhotoLibrary and the newMedia flag is set to false since the photo is already in the library we don t need to save it again IBAction func useCameraRoll sender AnyObject if UIImagePickerController isSourceTypeAvailable UIImagePickerControllerSourceType SavedPhotosAlbum let imagePicker UIImagePickerController imagePicker delegate self imagePicker sourceType UIImagePickerControllerSourceType PhotoLibrary imagePicker mediaTypes kUTTypeImage as String imagePicker allowsEditing false self presentViewController imagePicker animated true completion nil newMedia false Writing the Delegate Methods As described in Accessing the iOS 9 Camera and Photo Library in order to fully implement an instance of the image picker controller

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

  • IOS 9 Video Playback using AVPlayer and AVPlayerViewController - Techotopia
    be used instead of HTTP In recognition of the fact that not all servers support HTTPS it is possible to add an exception to the Info plist file of the app project This can be configured on a general basis or declared for individual domains To demonstrate this exception process in action the video file used in this example is stored on an HTTP based web server To add an exception for this server locate and select the Info plist file and set the properties as outlined in the figure below Figure 92 1 Alternatively Ctrl click on the Info plist file in the Project Navigator panel select Open As Source Code from the resulting menu and enter the following exception settings for the ebookfrenzy com domain key NSAppTransportSecurity key dict key NSExceptionDomains key dict key ebookfrenzy com key dict key NSIncludesSubdomains key true key NSTemporaryExceptionAllowsInsecureHTTPLoads key true key NSTemporaryExceptionMinimumTLSVersion key string TLSv1 1 string dict dict dict eBookFrenzy com Purchase the full edition of this iOS 9 App Development Essentials 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 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 With the button selected in the storyboard canvas display the Auto Layout Align menu and add both horizontal and vertical container constraints to the view with both offset values set to 0 From the Object Library panel locate the AVKit Player View Controller object and drag and drop it onto the storyboard to the right of the existing view controller Ctrl click on the button in the first view controller and drag the resulting line to the AVKit Player View Controller Release the line and select show from the segue selection menu On completion of these tasks the storyboard should resemble that of Figure 92 2 Figure 92 2 Initializing Video Playback When the Play Movie button is tapped by the user the application will perform a segue to the AVPlayerViewController scene Verify that this works by running the application and selecting the button The AVPlayerViewController will appear and display the video playback controls but as yet no AVPlayer has been configured to play video content This can be achieved by implementing the prepareForSegue method within the ViewController swift file as follows the code for which relies on the AVKit and AVFoundation frameworks having been imported import UIKit import AVKit import AVFoundation class ViewController UIViewController override func prepareForSegue segue UIStoryboardSegue sender AnyObject let destination segue destinationViewController as AVPlayerViewController let url NSURL string http www ebookfrenzy com ios book movie movie mov if let movieURL url destination player AVPlayer URL movieURL eBookFrenzy com Purchase the full edition of this iOS 9 App Development Essentials book in eBook 12 99 or Print 39 99 format iOS 9 App

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

  • An iOS 9 Multitasking Picture in Picture Tutorial - Techotopia
    UIApplication didFinishLaunchingWithOptions launchOptions NSObject AnyObject Bool let audioSession AVAudioSession sharedInstance do try audioSession setCategory AVAudioSessionCategoryPlayback catch print Unable to set audio session category return true With these steps completed launch the app on a physical iPad or iOS simulator session keeping in mind that PiP support is not available on the first generation iPad Mini or any full size iPad models older than the first iPad Air Once loaded tap the Play Movie button and start video playback Tap the PiP button in the video playback control bar or use the device Home button and note that video playback is transferred to the PiP window Figure 93 4 With the PiP window visible and the three control buttons displayed tap the button to toggle back to full screen playback mode PiP support is now implemented with the exception of one important step To experience the need for this additional step run the app once again begin movie playback and switch playback to PiP mode Remaining within the AVPlayerDemo app tap the Back button located in the navigation bar to return to the original view controller scene containing the Play Movie button Tap the PiP button to return the movie playback to full screen at which point the movie playback window will disappear leaving just the initial view controller visible The reason for this is that a delegate method needs to be implemented to present the full size video playback view controller in this situation Implementing the Delegate The AVPlayerViewController class can have assigned to it a delegate object on which methods will be called at various points during the playback of a video This delegate object must implement the AVPlayerViewControllerDelegate protocol For the purposes of this example the ViewController class will be designated as the delegate object for the class Select the ViewController swift file and modify it to declare that it now implements the AVPlayerViewControllerDelegate protocol import UIKit import AVKit import AVFoundation class ViewController UIViewController AVPlayerViewControllerDelegate override func viewDidLoad super viewDidLoad Do any additional setup after loading the view typically from a nib eBookFrenzy com Purchase the full edition of this iOS 9 App Development Essentials 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 Having declared that the class implements the protocol the prepareForSegue method now needs to be modified to assign the current instance of the class as the delegate for the player view controller instance override func prepareForSegue segue UIStoryboardSegue sender AnyObject let destination segue destinationViewController as AVPlayerViewController let url NSURL string http www ebookfrenzy com ios book movie movie mov destination delegate self if let movieURL url destination player AVPlayer URL movieURL When the user moves back from the PiP window to full screen playback mode the restoreUserInterfaceForPictureInPictureStopWithCompletionHandler method is called on the delegate object This method is passed a reference to the player view controller and a completion handler It is the responsibility of this method to make

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



  •