Slide 1

Slide 1 text

MonkeySquare 2012 October 17th 2012

Slide 2

Slide 2 text

A head start with MonoTouch 6

Slide 3

Slide 3 text

Chris Hardy • .NET Contractor • Work with Xamarin • Wrote some books • First spoke about MonoTouch in January 2010 • http://twitter.com/chrisntr

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

MonoTouch 6.0 Earnest

Slide 7

Slide 7 text

MonkeySpace ConfApp github.com/conceptdev/MonkeySpace

Slide 8

Slide 8 text

MonkeySpace ConfApp github.com/chrisntr/MonkeySpace iOS 6 version up on GitHub

Slide 9

Slide 9 text

What’s new for developers?

Slide 10

Slide 10 text

What’s new for developers? • Social • UIKit Improvements • Maps • Reminders • UICollectionView • PassKit

Slide 11

Slide 11 text

No more Snow Leopard NO

Slide 12

Slide 12 text

No more Snow Leopard • Xcode 4.5/ iOS 6.0 works on Lion and Mountain Lion, requires MonoTouch 6.0 • Xcode 4.5 removes support for ARMv6 devices • Xcode 4.4 / iOS 5.1.1 works on Snow Leopard, Lion and Mountain Lion with MonoTouch 5.4 and can build for ARMv6 devices • ARMv6 devices = iPhone (1st Generation), iPhone 3G, iPod Touch (1st and 2nd Generation) • Download Xcode 4.4 and install in /Applications/Xcode44.app and change location in MonoDevelop’s ‘SDK Locations’

Slide 13

Slide 13 text

Good news for developers http://tcrn.ch/RQbjVY iOS 5.1.1 = iOS 6.0 =

Slide 14

Slide 14 text

Handling the iPhone 5 MonoDevelop 3.0.5 adds support Add a [email protected] named image

Slide 15

Slide 15 text

Handling the iPhone 5 Referencing “Default.png” splashView = new UIImageView(new RectangleF(0f, 0f, 320f, 480f)); splashView.Image = UIImage.FromFile("Default.png");

Slide 16

Slide 16 text

Handling the iPhone 5 Referencing “Default.png” splashView = new UIImageView(new RectangleF(0f, 0f, 320f, 480f)); splashView.Image = UIImage.FromFile("Default.png"); splashView = new UIImageView(UIScreen.MainScreen.Bounds); if (UIScreen.MainScreen.Bounds.Height > 480f) splashView.Image = UIImage.FromFile("[email protected]"); else splashView.Image = UIImage.FromFile("Default.png"); Becomes

Slide 17

Slide 17 text

MonkeySpace 2012 Demo

Slide 18

Slide 18 text

Social Framework Twitter in iOS 5

Slide 19

Slide 19 text

Social Framework Twitter in iOS 5 var tweet = new TWTweetComposeViewController(); tweet.SetInitialText ("I'm in '" + DisplaySession.Title + "' at #monkeyspace" ); PresentModalViewController(tweet, true); if (TWTweetComposeViewController.CanSendTweet) { // Do Tweet option displaying here } Check for Twitter access

Slide 20

Slide 20 text

Social Framework Twitter, Facebook and SinaWeibo in iOS 6 if (UIDevice.CurrentDevice.CheckSystemVersion(6,0) && SLComposeViewController.IsAvailable(SLServiceKind.Facebook)) { // Do Facebook option displaying here } var facebook = SLComposeViewController.FromService(SLServiceKind.Facebook); facebook.SetInitialText("I'm in '" + DisplaySession.Title + "' at #monkeyspace" ); PresentViewController(facebook, true, null);

Slide 21

Slide 21 text

Social Framework Twitter, Facebook and Weibo in iOS 6

Slide 22

Slide 22 text

MonkeySpace 2012 Demo

Slide 23

Slide 23 text

Social Framework UIActivityViewController from UIKit var message = "I'm in '" + DisplaySession.Title + "' at #monkeyspace"; var social = new UIActivityViewController(new NSObject[] { new NSString(message) }, new UIActivity[] { new UIActivity() }); PresentViewController(social, true, null); • Provide multiple objects - Strings, Images, Custom data that implement UIActivityItemSource • Include types of Activities you want to share with, can exclude activities such as PostToFacebook or E-mail

Slide 24

Slide 24 text

Social Framework UIActivityViewController all the social networks

Slide 25

Slide 25 text

MonkeySpace 2012 Demo

Slide 26

Slide 26 text

UIKit Improvements Pull To Refresh - Side by Side comparison

Slide 27

Slide 27 text

UIKit Improvements UIRefreshControl • Implement ValueChanged event • Handle Being/EndRefreshing • Optional Title and TintColor NavigationItem.SetRightBarButtonItem (new UIBarButtonItem (UIBarButtonSystemItem.Refresh), false); NavigationItem.RightBarButtonItem.Clicked += (sender, e) => { Refresh(); }; Becomes if (UIDevice.CurrentDevice.CheckSystemVersion (6,0)) { // Display UIRefreshControl here } else if { NavigationItem.SetRightBarButtonItem (new UIBarButton.... NavigationItem.RightBarButtonItem.Clicked += (sender, e) => ... }

Slide 28

Slide 28 text

UIKit Improvements UIRefreshControl RefreshControl = new UIRefreshControl(); RefreshControl.ValueChanged += HandleValueChanged; AppDelegate.Conference.OnDownloadSucceeded += (jsonString) => { Console.WriteLine ("OnDownloadSucceeded"); InvokeOnMainThread (() => { RefreshControl.EndRefreshing (); }); }; AppDelegate.Conference.OnDownloadFailed += (err) => { Console.WriteLine ("OnDownloadFailed"); InvokeOnMainThread (() => { RefreshControl.EndRefreshing (); }); };

Slide 29

Slide 29 text

MonkeySpace 2012 Demo

Slide 30

Slide 30 text

Maps

Slide 31

Slide 31 text

Maps

Slide 32

Slide 32 text

Maps • New Class - MKMapItem • Maps app in the simulator • Can send MKMapItems to the Maps app • Can receive MKMapItem data from

Slide 33

Slide 33 text

Maps Sending data to the Maps app if(UIDevice.CurrentDevice.CheckSystemVersion(6,0)) segmentedControl.InsertSegment ("Directions", 3, false); var conferenceMapItem = new MKMapItem(new MKPlacemark(ConferenceLocation, null)); conferenceMapItem.Name = "MonkeySpace"; var conferenceHotel = new MKMapItem(new MKPlacemark(new CLLocationCoordinate2D(42.36346, -71.0863), null)); conferenceHotel.Name = "MonkeySpace Hotel"; var mapItems = new MKMapItem[] { conferenceMapItem, conferenceHotel }; MKMapItem.OpenMaps(mapItems, new MKLaunchOptions() { DirectionsMode = MKDirectionsMode.Walking });

Slide 34

Slide 34 text

MonkeySpace 2012 Demo

Slide 35

Slide 35 text

Maps Receiving data from the Maps app 1. Create a GeoJson file with “.geojson” extension { "type": "MultiPolygon", "coordinates": [ [[[-122.7, 37.3], [-121.9, 37.3], [-121.9, 37.9], [-122.7, 37.9], [-122.7, 37.3]]], [[[-87.9, 41.5], [-87.3, 41.5], [-87.3, 42.1], [-87.9, 42.1], [-87.9, 41.5]]] ] }

Slide 36

Slide 36 text

Maps Receiving data from the Maps app 2. Set the Maps options in the plist file (MonoDevelop 3.0.5+)

Slide 37

Slide 37 text

Maps Receiving data from the Maps app 3. Override OpenUrl on AppDelegate and check for Url if (MKDirectionsRequest.IsDirectionsRequestUrl (url)) { var request = new MKDirectionsRequest(url); // Do something with the request }

Slide 38

Slide 38 text

MonkeySpace 2012 Demo

Slide 39

Slide 39 text

Reminders App.Current.EventStore.RequestAccess (EKEntityType.Reminder, (bool granted, NSError e) => { if (granted) { // Create a EKReminder and save reminder } else { new UIAlertView ( "Access Denied", "No Access", null, "OK", null).Show (); } ); • EKReminder is part of EventKit, subclasses EKCalendarItem • Need to request access to Reminders for Read/Write • Fetch, Save, Delete Reminders and with Predicates for searching Add a reminder for session

Slide 40

Slide 40 text

Reminders Add a reminder for session EKReminder reminder = EKReminder.Create (App.Current.EventStore); reminder.Title = DisplaySession.Title; reminder.Calendar = App.Current.EventStore.DefaultCalendarForNewReminders; reminder.Notes = DisplaySession.Abstract; var date = new NSDateComponents(); date.Day = DisplaySession.Start.Day; date.Month = DisplaySession.Start.Month; date.Year = DisplaySession.Start.Year; date.Hour = DisplaySession.Start.Hour; date.Minute = DisplaySession.Start.Minute; date.Second = DisplaySession.Start.Second; reminder.StartDateComponents = date; reminder.DueDateComponents = date; App.Current.EventStore.SaveReminder (reminder, true, out e);

Slide 41

Slide 41 text

MonkeySpace 2012

Slide 42

Slide 42 text

UICollectionView View Bing images uploaded with the name “monkeyspace” • UITableView for a collection of items • Handles layout automatically, can be customized with UICollectionViewFlowLayout

Slide 43

Slide 43 text

UICollectionView View Bing images uploaded with the name “monkeyspace” • Override ViewDidLoad to handle registering classes • Override GetItemCount • Override GetCell • Can override ItemSelected, ItemDeselected, ItemHighlighted, ItemUnhighlighted • Can override GetViewForSupplementaryElement to display a “Header” or “Section” view.

Slide 44

Slide 44 text

MonkeySpace 2012 Demo

Slide 45

Slide 45 text

PassKit An overview

Slide 46

Slide 46 text

PassKit An overview • Types - Event Ticket, Boarding Pass, Store Card, Coupon or Generic • ZIP file containing JSON files, optional images and localization strings • Can contain a Barcode, Location, Date Time and more • Passes are signed against a Apple certificate and identifier • Can be sent using E-mail, Link on a Website, Through an App

Slide 47

Slide 47 text

PassKit An overview

Slide 48

Slide 48 text

PassKit Check availability of the PKPassLibrary if (PKPassLibrary.IsAvailable) { // Display PassKit views } library = new PKPassLibrary (); noteCenter = NSNotificationCenter.DefaultCenter.AddObserver (PKPassLibrary.DidChangeNotification, (not) => { BeginInvokeOnMainThread (() => { // refresh the pass passes = library.GetPasses (); RenderPass(passes); }); }, library); passes = library.GetPasses (); RenderPass(passes); Get the passes for the application

Slide 49

Slide 49 text

MonkeySpace 2012 Demo

Slide 50

Slide 50 text

To Recap •Social •UIKit Improvements •Maps •Reminders •UICollectionView •PassKit

Slide 51

Slide 51 text

References •github.com/chrisntr/monkeyspace •docs.xamarin.com •dev.apple.com

Slide 52

Slide 52 text

Q & A Thanks!