Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A head start with MonoTouch 6.0

42a225596034ac0108c0b4dade5c7be5?s=47 Chris Hardy
October 18, 2012

A head start with MonoTouch 6.0

MonkeySpace 2012 presentation on "A head start with MonoTouch 6.0"

42a225596034ac0108c0b4dade5c7be5?s=128

Chris Hardy

October 18, 2012
Tweet

Transcript

  1. MonkeySquare 2012 October 17th 2012

  2. A head start with MonoTouch 6

  3. Chris Hardy • .NET Contractor • Work with Xamarin •

    Wrote some books • First spoke about MonoTouch in January 2010 • http://twitter.com/chrisntr
  4. None
  5. None
  6. MonoTouch 6.0 Earnest

  7. MonkeySpace ConfApp github.com/conceptdev/MonkeySpace

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

  9. What’s new for developers?

  10. What’s new for developers? • Social • UIKit Improvements •

    Maps • Reminders • UICollectionView • PassKit
  11. No more Snow Leopard NO

  12. 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’
  13. Good news for developers http://tcrn.ch/RQbjVY iOS 5.1.1 = iOS 6.0

    =
  14. Handling the iPhone 5 MonoDevelop 3.0.5 adds support Add a

    Default-568h@2x.png named image
  15. Handling the iPhone 5 Referencing “Default.png” splashView = new UIImageView(new

    RectangleF(0f, 0f, 320f, 480f)); splashView.Image = UIImage.FromFile("Default.png");
  16. 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("Default-568h@2x.png"); else splashView.Image = UIImage.FromFile("Default.png"); Becomes
  17. MonkeySpace 2012 Demo

  18. Social Framework Twitter in iOS 5

  19. 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
  20. 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);
  21. Social Framework Twitter, Facebook and Weibo in iOS 6

  22. MonkeySpace 2012 Demo

  23. 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
  24. Social Framework UIActivityViewController all the social networks

  25. MonkeySpace 2012 Demo

  26. UIKit Improvements Pull To Refresh - Side by Side comparison

  27. 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) => ... }
  28. 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 (); }); };
  29. MonkeySpace 2012 Demo

  30. Maps

  31. Maps

  32. Maps • New Class - MKMapItem • Maps app in

    the simulator • Can send MKMapItems to the Maps app • Can receive MKMapItem data from
  33. 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 });
  34. MonkeySpace 2012 Demo

  35. 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]]] ] }
  36. Maps Receiving data from the Maps app 2. Set the

    Maps options in the plist file (MonoDevelop 3.0.5+)
  37. 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 }
  38. MonkeySpace 2012 Demo

  39. 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
  40. 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);
  41. MonkeySpace 2012

  42. UICollectionView View Bing images uploaded with the name “monkeyspace” •

    UITableView for a collection of items • Handles layout automatically, can be customized with UICollectionViewFlowLayout
  43. 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.
  44. MonkeySpace 2012 Demo

  45. PassKit An overview

  46. 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
  47. PassKit An overview

  48. 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
  49. MonkeySpace 2012 Demo

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

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

  52. Q & A Thanks!