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

CodeFest 2019. Иван Шевелев (2ГИС) — iOS. Как м...

CodeFest
April 06, 2019

CodeFest 2019. Иван Шевелев (2ГИС) — iOS. Как мы запустили 2ГИС под CarPlay и до сих пор расхлебываем

Когда на WWDC 2018 анонсировали возможность создания навигационных приложений под Apple CarPlay, мы решили засунуть наш навигатор пользователям в автомобили. Однако, уже начиная с Keynote, Apple начала вставлять нам палки в колеса.

Я расскажу, как начать разработку под CarPlay, с чем придётся столкнуться и какие костыли придется навертеть из-за багов в CarPlay.framework. Поговорим о документации, инструментах разработки и семпл-приложении с WWDC.

CodeFest

April 06, 2019
Tweet

More Decks by CodeFest

Other Decks in Technology

Transcript

  1. Как мы запустили 2ГИС под CarPlay и до сих пор

    расхлебываем Иван, Шевелев iOS Разработчик 2ГИС
  2. !4

  3. 5

  4. 9

  5. 17

  6. 18

  7. CPApplicationDelegate func application( _ application: UIApplication, didConnectCarInterfaceController controller: CPInterfaceController, to

    window: CPWindow ) { } let carMapViewController = CarMapViewController( interfaceController: controller ) let navigationController = UINavigationController( rootViewController: carMapViewController ) window.rootViewController = navigationController 19 func application( _ application: UIApplication, didDisconnectCarInterfaceController controller: CPInterfaceController, from window: CPWindow ) {}
  8. 21

  9. 26

  10. let zoomInButton = CPMapButton(…) let zoomOutButton = CPMapButton(…) let myLocationButton

    = CPMapButton(…) self.mapTemplate.mapButtons = [ zoomInButton, zoomOutButton, myLocationButton ] 29
  11. 30

  12. 31

  13. 33

  14. let choice1 = CPRouteChoice( summaryVariants: ["46 км"], additionalInformationVariants: ["с учетом

    пробок"], selectionSummaryVariants: [“1 час 11 мин"] ) let choice0 = CPRouteChoice( summaryVariants: ["46 км"], additionalInformationVariants: ["с учетом пробок"], selectionSummaryVariants: ["1 час 7 мин"] ) 34
  15. let startItem = MKMapItem(…) let endItem = MKMapItem(…) endItem.name =

    "Толмачёво, международный аэропорт" 35
  16. let trip = CPTrip( origin: startItem, destination: endItem, routeChoices: [choice0,

    choice1] ) self.mapTemplate.showTripPreviews( [trip], textConfiguration: tripPreviewTextConfiguration ) let tripPreviewTextConfiguration = CPTripPreviewTextConfiguration( startButtonTitle: "В путь”, additionalRoutesButtonTitle: “Ещё”, overviewButtonTitle: "Назад" ) 36
  17. 37

  18. func mapTemplate( _ mapTemplate: CPMapTemplate, startedTrip trip: CPTrip, using routeChoice:

    CPRouteChoice ) { } self.navigationSession = self.mapTemplate.startNavigationSession(for: trip) 38
  19. maneuver.symbolSet = CPImageSet( lightContentImage: icon, darkContentImage: darkIcon ) maneuver.instructionVariants =

    ["Ул. Кутателадзе”] maneuver.initialTravelEstimates = CPTravelEstimates(…) self.navigationSession?.upcomingManeuvers = [maneuver] let estimates = CPTravelEstimates(…) self.navigationSession?.updateEstimates(estimates, for: maneuver) let maneuver = CPManeuver() 39
  20. 41

  21. 42

  22. 43

  23. 45

  24. ⚙ Code Signing Error: Automatic signing is unable to resolve

    an issue with the "v4ios" target's entitlements. Automatic signing can't add the com.apple.developer.carplay-maps entitlement to your provisioning profile. Switch to manual signing and resolve the issue by downloading a matching provisioning profile from the developer website. 46
  25. 47

  26. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported object

    <YourAwesomeGridTemplate: 0x60000060dce0> <identifier: 6CAC7E3B-FE70-43FC-A8B1-8FC39334A61D, userInfo: (null)> passed to pushTemplate:animated:. Allowed classes: {( CPListTemplate, CPGridTemplate, CPSearchTemplate, CPMapTemplate )}' 52
  27. 56

  28. Connect CarPlay Подписка на состояние батареи Disconnect Получение уведомления и

    создание таймера Выстрел таймера Возвращение карты, отписка от состояния батареи, уничтожение таймера 59
  29. Connect CarPlay Подписка на состояние батареи Disconnect Получение уведомления и

    создание таймера Возвращение карты, отписка от состояния батареи, уничтожение таймера 60
  30. 61

  31. 63

  32. Navigation apps are designed to work with a variety of

    car input devices, and CarPlay does not support direct user interaction in the base view (apps do not directly receive tap or drag events). 64
  33. CPMapTemplateDelegate /** Called when a pan gesture begins. May not

    be called when connected to some CarPlay systems. */ optional public func mapTemplateDidBeginPanGesture(_ mapTemplate: CPMapTemplate) /** Called when a pan gesture changes. May not be called when connected to some CarPlay systems. */ optional public func mapTemplate(_ mapTemplate: CPMapTemplate, didUpdatePanGestureWithTranslation translation: CGPoint, velocity: CGPoint ) /** Called when a pan gesture ends. May not be called when connected to some CarPlay systems. */ optional public func mapTemplate(_ mapTemplate: CPMapTemplate, didEndPanGestureWithVelocity velocity: CGPoint ) 66
  34. 67

  35. 68

  36. 70

  37. 72