xamarin: introduction to ios 8

40
iOS 8 Overview September 11, 2014 @mikebluestein

Upload: xamarin

Post on 01-Nov-2014

1.513 views

Category:

Technology


4 download

DESCRIPTION

Get ready for iOS 8 with this introduction from Xamarin Evangelist Mike Bluestein.

TRANSCRIPT

Page 1: Xamarin: Introduction to iOS 8

iOS 8 Overview

September 11, 2014

@mikebluestein

Page 2: Xamarin: Introduction to iOS 8

Agenda▪ Alert Controller

▪ Navigation Controller

▪ Notification Settings

▪ Notification Actions

▪ Popover Presentation Controller

▪ Search Controller

▪ Split View Controller

▪ Visual Effects

▪ Collection Views

▪ Document Picker

▪ Health Kit

▪ Core Image

▪ Scene Kit

▪ Photo Kit

Page 3: Xamarin: Introduction to iOS 8

Alert Controller

▪UIAlertViewController ▪Replaces UIActionSheet and

UIAlertView

iOS 8 Major Features

Page 4: Xamarin: Introduction to iOS 8

Alert Controller

Page 5: Xamarin: Introduction to iOS 8

Alert Controller

public static UIAlertController PresentOKAlert( string title, string description, UIViewController controller) { // No, inform the user that they must create a home first var alert = UIAlertController.Create (title, description, UIAlertControllerStyle.Alert); ! // Configure the alert alert.AddAction(UIAlertAction.Create (“OK", UIAlertActionStyle.Default,(action) => {})); ! // Display the alert controller.PresentViewController (alert, true, null); ! // Return created controller return alert; } !... !// Display the Alert AlertView.PresentOKAlert ("OK Alert”, "This is a sample alert with an OK button.”, this);

Page 6: Xamarin: Introduction to iOS 8

Navigation Controller

▪Change navigation bar size ▪Hide navigation bar with gestures

iOS 8 Major Features

Page 7: Xamarin: Introduction to iOS 8

Navigation Controller

public override void ViewWillAppear (bool animated) { base.ViewWillAppear (animated); ! // Set the default mode NavigationController.HidesBarsOnTap = true; ! // Wireup segment controller NavBarMode.ValueChanged += (sender, e) => { // Take action based on the selected mode switch(NavBarMode.SelectedSegment) { case 0: NavigationController.HidesBarsOnTap = true; NavigationController.HidesBarsOnSwipe = false; break; case 1: NavigationController.HidesBarsOnTap = false; NavigationController.HidesBarsOnSwipe = true; break; } }; }

Page 8: Xamarin: Introduction to iOS 8

Notification Settings

▪UIUserNotificationSetting ▪Encapsulates notification types ▪UIUserNotifiationType – Alert, Badge,

Sound

iOS 8 Major Features

Page 9: Xamarin: Introduction to iOS 8

Notification Settings

// Set the requested notification types UIUserNotificationType type = UIUserNotificationType.Alert | UIUserNotificationType.Badge; !// Create the setting for the given types UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes(type, categories); !// Register the settings UIApplication.SharedApplication.RegisterUserNotificationSettings ( settings);

Page 10: Xamarin: Introduction to iOS 8

Notification Actions

▪UIMutableUserNotificationAction ▪Custom action in response

to notification

iOS 8 Major Features

Page 11: Xamarin: Introduction to iOS 8

Notification Actions

var acceptAction = new UIMutableUserNotificationAction { Identifier = "ACCEPT_ID", Title = "Accept", ActivationMode = UIUserNotificationActivationMode.Background, Destructive = false, AuthenticationRequired = false }; !var trashAction = new UIMutableUserNotificationAction { Identifier = "TRASH_ID", Title = "Trash", ActivationMode = UIUserNotificationActivationMode.Background, Destructive = true, AuthenticationRequired = true };

Page 12: Xamarin: Introduction to iOS 8

Popover Presentation

Controller

▪UIPopoverPresentationController ▪Manages popover content

▪Modal view on iPhone

iOS 8 Major Features

Page 13: Xamarin: Introduction to iOS 8

Popover Presentation Controller

vc.ModalPresentationStyle = UIModalPresentationStyle.Popover; !... !PresentViewController(vc, true, null); !UIPopoverPresentationController popoverController = vc.PopoverPresentationController; !if (popoverController!=null) { popoverController.SourceView = View; popoverController.PermittedArrowDirections = UIPopoverArrowDirection.Up; popoverController.SourceRect = ShowButton.Frame; }

Page 14: Xamarin: Introduction to iOS 8

Search Controller

▪ UISearchController ▪ Replaces UISearchDisplayController ▪ UISearchResultsUpdating updates results ▪ Results can be displayed in any view

as needed

iOS 8 Major Features

Page 15: Xamarin: Introduction to iOS 8

Search Controller

// Create search updater var searchUpdater = new SearchResultsUpdator (); searchUpdater.UpdateSearchResults += (searchText) => { // Perform search and reload search table searchSource.Search(searchText); searchResultsController.TableView.ReloadData(); }; !// Create a search controller SearchController = new UISearchController (searchResultsController); SearchController.SearchResultsUpdater = searchUpdater; !... !public class SearchResultsUpdator : UISearchResultsUpdating { public override void UpdateSearchResultsForSearchController (UISearchController searchController) { // Inform caller of the update event RaiseUpdateSearchResults (searchController.SearchBar.Text); } ... }

Page 16: Xamarin: Introduction to iOS 8

Split View Controller

▪ UISplitViewController ▪ Now works on iPad and iPhone

▪ PreferredDisplayMode • AllVisible, PrimaryHidden, PrimaryOverlay

iOS 8 Major Features

Page 17: Xamarin: Introduction to iOS 8

Split View Features

public class Controller : UISplitViewController { public override void ViewDidLoad () { base.ViewDidLoad (); ! PreferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible; } }

Page 18: Xamarin: Introduction to iOS 8

Visual Effects▪UIVisualEffect ▪Blur and Vibrancy

• UIVibrancyEffect • UIBlurEffect

iOS 8 Major Features

Page 19: Xamarin: Introduction to iOS 8

Visual Effects

// blur view var blur = UIBlurEffect.FromStyle (UIBlurEffectStyle.Light); var blurView = new UIVisualEffectView (blur) { Frame = new RectangleF (0, 0, imageView.Frame.Width, 400) }; !View.Add (blurView); !// vibrancy view var frame = new Rectangle (10, 10, 100, 50); var vibrancy = UIVibrancyEffect.FromBlurEffect (blur); var vibrancyView = new UIVisualEffectView (vibrancy) { Frame = frame }; !vibrancyView.ContentView.Add (label); blurView.ContentView.Add (vibrancyView);

Page 20: Xamarin: Introduction to iOS 8

Collection Views

▪ Self-sizing cells

▪ UICollectionViewFlowLayout • EstimatedItemSize

▪ UICollectionViewDelegateFlowLayout • SizeThatFits

iOS 8 Major Features

Page 21: Xamarin: Introduction to iOS 8

Collection Views

flowLayout = new UICollectionViewFlowLayout (){ EstimatedItemSize = new SizeF (44, 144) }; !... !public override SizeF SizeThatFits (SizeF size) { label.Frame = new RectangleF (new PointF (0, 0), label.AttributedText.Size); return label.AttributedText.Size; }

Page 22: Xamarin: Introduction to iOS 8

Document Picker

▪ UIDocumentPickerController ▪ Select documents outside app sandbox ▪ User can open and documents directly

iOS 8 Major Features

Page 23: Xamarin: Introduction to iOS 8

Document Picker

!var allowedUTIs = new string[] { UTType.PDF, UTType.Image, ... }; !var pickerMenu = new UIDocumentMenuViewController(allowedUTIs, UIDocumentPickerMode.Open); !pickerMenu.DidPickDocumentPicker += (sender, args) => { ! args.DocumentPicker.DidPickDocument += (s, pArgs) => { ! var securityEnabled = pArgs.Url.StartAccessingSecurityScopedResource(); ! ThisApp.OpenDocument(pArgs.Url); ! pArgs.Url.StopAccessingSecurityScopedResource(); }; ! // Display the document picker PresentViewController (args.DocumentPicker, true, null); };

Page 24: Xamarin: Introduction to iOS 8

Health Kit

▪ Store and Share Health Data ▪ Create Data ▪ Save Data ▪ Query Data

iOS 8 Major Features

Page 25: Xamarin: Introduction to iOS 8

▪ HKUnit

• represents a unit of measure ▪ HKQuantity

• double value relative to a unit • can be used for conversion

Health Kit Classes

▪ HKObjectType

• represent different kinds of data that can be stored

▪ HKObject

• All data stored is a subclass of HKObject

Page 26: Xamarin: Introduction to iOS 8

▪ HKHealthStore - link to the health database

▪ Check Health Kit availability on device

▪ Authorize Health Kit

▪ Save and Query data

▪ Query via HKQuery

Health Store

Page 27: Xamarin: Introduction to iOS 8

Authorize

// authorization if (HKHealthStore.IsHealthDataAvailable) { var temperatureKey = HKQuantityTypeIdentifierKey.BodyTemperature; var tempQuantityType = HKObjectType.GetQuantityType (temperatureKey); ! var healthStore = new HKHealthStore (); ! healthStore.RequestAuthorizationToShare ( new NSSet (new [] { tempQuantityType }), new NSSet (), (success, error) => { ! }); }

Page 28: Xamarin: Introduction to iOS 8

Save

// save data var temp = HKQuantity.FromQuantity ( HKUnit.DegreeFahrenheit, 99.9); !var meta = NSDictionary.FromObjectAndKey ( new NSNumber (4), HKMetadataKey.BodyTemperatureSensorLocation); !var sample = HKQuantitySample.FromType ( tempQuantityType, temp, new NSDate (), new NSDate (), meta); !healthStore.SaveObject (sample, (success, err) => { ... });

Page 29: Xamarin: Introduction to iOS 8

Query

// query data var temperatureType = HKObjectType.GetQuantityType (HKQuantityTypeIdentifierKey.BodyTemperature) as HKSampleType; !//Sort descending, by end date (i.e., last sample) var sortDescriptor = new NSSortDescriptor (HKSample.SortIdentifierEndDate, false); new HKSampleQuery (temperatureType, null, 1, new [] { sortDescriptor }, ResultsHandler); !protected void ResultsHandler (HKSampleQuery query, HKSample[] results, NSError error) { ... }

Page 30: Xamarin: Introduction to iOS 8

Core Image▪ New QR code and Rectangle detectors ▪ New Filters ▪ Custom Filters ▪ Feature detection in video

iOS 8 Major Features

Page 31: Xamarin: Introduction to iOS 8

Core Image Detectors

▪ Previously only facial detection ▪ Now Rectangle and QR code detectors ▪ CIDetector.CreateRectangleDetector ▪ CIDetector.CreateQRDetector

Page 32: Xamarin: Introduction to iOS 8

Save

var context = CIContext.FromOptions (null); var options = new CIDetectorOptions { Accuracy = FaceDetectorAccuracy.High }; !var detector = CIDetector.CreateRectangleDetector (context, options); var ciImage = CIImage.FromCGImage (imageIn.CGImage); var features = detector.FeaturesInImage (ciImage); !var overlay = CIImage.ImageWithColor (CIColor.FromRgba (1.0f, 0.0f, 0.0f, 0.7f)); !overlay = overlay.ImageByCroppingToRect (features [0].Bounds); var ciImageWithOverlay = overlay.CreateByCompositingOverImage (ciImage);

Page 33: Xamarin: Introduction to iOS 8

Scene Kit

▪ 3D Scene Graph ▪ Casual 3D Games ▪ 3D Visualizations ▪ Abstracts OpenGL ES

iOS 8 Major Features

Page 34: Xamarin: Introduction to iOS 8

Scene Kit

Page 35: Xamarin: Introduction to iOS 8

Scene Kit

// scene scene = SCNScene.Create (); sceneView = new SCNView (View.Frame); sceneView.Scene = scene; !sphere = SCNSphere.Create (10.0f); sphereNode = SCNNode.FromGeometry (sphere); sphereNode.Position = new SCNVector3 (0, 0, 0); scene.RootNode.AddChildNode (sphereNode); !// omni-directional light var light = SCNLight.Create (); var lightNode = SCNNode.Create (); light.LightType = SCNLightType.Omni; light.Color = UIColor.Blue; lightNode.Light = light; lightNode.Position = new SCNVector3 (-40, 40, 60); scene.RootNode.AddChildNode (lightNode);

// ambient light ambientLight = SCNLight.Create (); ambientLightNode = SCNNode.Create (); ambientLight.LightType = SCNLightType.Ambient; ambientLight.Color = UIColor.Purple; ambientLightNode.Light = ambientLight; scene.RootNode.AddChildNode (ambientLightNode); !// camera camera = new SCNCamera { XFov = 80, YFov = 80 }; cameraNode = new SCNNode { Camera = camera, Position = new SCNVector3 (0, 0, 40) }; scene.RootNode.AddChildNode (cameraNode)

Page 36: Xamarin: Introduction to iOS 8

Photo Kit

▪ Framework to work with photo and video assets

▪ Fetch Results - PHAsset.FetchAssets

▪ Write Changes - PhotoLibraryObserver

iOS 8 Major Features

Page 37: Xamarin: Introduction to iOS 8

DEMO

Page 38: Xamarin: Introduction to iOS 8

Much More▪ Manual Camera Controls

▪ Home Kit

▪ Cloud Kit

▪ Handoff

▪ Touch ID Auth

▪ App Extensions

▪ Unified Storyboards

▪ Sprite Kit

▪ Metal

▪ Apple Pay

Page 39: Xamarin: Introduction to iOS 8

Much More

http://developer.xamarin.com/guides/ios/platform_features/introduction_to_ios_8/

Page 40: Xamarin: Introduction to iOS 8

Key Attendees