Apple CarPlay P1

by TienVV8
108 views

Hi. Apple CarPlay không còn xa lạ với nhiều người, đặc biệt là các anh em sử dụng xe hàng ngày. Vậy làm sao để một ứng dụng hỗ trợ CP? (CarPlay). Trong bài này mình sẽ giới thiệu đến anh em về CP.

CP là gì?

CP là một cách an toàn để sử dụng iPhone trên xe ô tô, CP sẽ thực hiện các tác vụ mà người dùng muốn thực hiện với iPhone trong khi lái xe.

CP Types

Ở thời điểm hiện tại Apple cung cấp 9 CP types

  • Audio
  • Communication (Messaging & calling)
  • Driving task
  • EV charging
  • Fueling
  • Navigation
  • Packing
  • Quick food ordering
  • Automaker

Đến đây chắc hẳn các bạn cũng thắc mắc tại sao type Automaker mình lại highlight lên như vậy. Thì đây là một type rất đặc biệt. Và ở phần 1 này mình chỉ chia sẻ về 8 types bên trên, riêng type Automaker mình sẽ chia sẻ ở phần tiếp theo.

Mỗi CP type sẽ có một entitlement key, key này chính là để enable/disable tính năng CP trong các ứng dụng

EntitlementKeyMinimum version
CarPlay Audio App (CarPlay framework)
App supports the CarPlay framework. Include both CarPlay audio app entitlements if your app supports the CarPlay framework and the Media Player framework.
com.apple.developer.carplay-audio
iOS 14
CarPlay Audio App (Media Player framework)
Deprecated. App supports the Media Player framework. Include both CarPlay audio app entitlements if your app supports the CarPlay framework and the Media Player framework.
com.apple.developer.playable-content
CarPlay Communication App
App supports the CarPlay framework, and SiriKit intents for messaging or VoIP calling apps. May be combined with the optional CarPlay Messaging App and CarPlay VoIP Calling App entitlements to support iOS 13 and earlier.
com.apple.developer.carplay-communicationiOS 14
CarPlay Messaging App
Deprecated. App relies solely on SiriKit and supports SiriKit intents to send, request, and modify messages. May be combined with the CarPlay Communication App entitlement, and the optional CarPlay VoIP Calling App entitlement to support iOS 13 and earlier.
com.apple.developer.carplay-messaging
CarPlay VoIP Calling App
Deprecated. App relies solely on SiriKit and CallKit, and supports SiriKit intents for starting calls and requesting a list of calls. May be combined with the CarPlay Communication App entitlement, and the optional CarPlay Messaging App entitlement to support iOS 13 and earlier.
com.apple.developer.carplay-calling
CarPlay Driving Task App
App supports the CarPlay framework.
com.apple.developer.carplay-driving-taskiOS 16
CarPlay EV Charging App
App supports the CarPlay framework. May be combined with the CarPlay Fueling App entitlement.
com.apple.developer.carplay-chargingiOS 14
CarPlay Fueling App
App supports the CarPlay framework. May be combined with the CarPlay EV Charging App entitlement.
com.apple.developer.carplay-fuelingiOS 16
CarPlay Navigation App
App supports the CarPlay framework.
com.apple.developer.carplay-mapsiOS 12
CarPlay Parking App
App supports the CarPlay framework.
com.apple.developer.carplay-parkingiOS 14
CarPlay Quick Food Ordering App
App supports the CarPlay framework.
com.apple.developer.carplay-quick-orderingiOS 14
đây là các key của 8 types được cung cấp bưởi Apple

Note: Khi xây dựng một ứng dụng có hỗ trợ CP, thì chúng ta chỉ được chọn một trong 8 type này. Và config với key tương ứng trong file entitlement, như vậy là compiler đã hiểu là ứng dụng này có hỗ trợ CP.

CP Templates

Apple cung cấp 12 templates để hiển thị trên CP. Chúng ta không thể thay đổi layout của của các template này mà chỉ có thể input data vào để hiển thị.

  1. Action Sheet
  2. Alert
  3. Grid
  4. List
  5. Tab bar
  6. Information
  7. Point of interest
  8. Now Playing
  9. Contact
  10. Map
  11. Search
  12. Voice control

Hình ảnh của các templates có đầy đủ ở page 18, 19, 20, 21, 22, 23, 24

Mối quan hệ giữa CP Types và CP Templates

Ở trên mình đã giới thiệu đến các bạn types và templates trong CP. Vậy nó có mối quan hệ gì với nhau không?

Câu trả lời là có, mỗi CP type sẽ hỗ trợ một vài templates.

Ví dụ: với những ứng dụng CP Audio thì chỉ có thể hiển thị được với các templates như Alert, Grid, List, Tab bar, Now Playing

Trong trường hợp chọn một template không hỗ trợ để hiển thị thì app sẽ crash.

Ví dụ: ứng dụng CP Audio không hỗ trợ type Action Sheet, nếu chúng ta sử dụng type Action Sheet để hiển thị thì ứng dụng CP sẽ crash.

Di chuyển màn hình

  • Như một ứng dụng chạy trên iPhone, thì CP cũng có thể di chuyển màn hình bằng hai phương thức chính là push và present. Nhưng bản chất ở đây là di chuyển giữa các templates
    Ví dụ: Chúng ta xây dựng ứng dụng CP Audio, màn hình root view là List template, khi bấm vào một item trong list thì di chuyển đến template Now Playing thì đơn giản là chúng ta sử dụng phương thức push hoặc present để di chuyển.
  • Không phải template nào cũng có thể push và present được.
    Ví dụ: khi các bạn push đên Grid template thì không vấn đề gì, còn khi các bạn present đến Grid thì CP sẽ crash và báo present không support Grid.
  • limit khi di chuyển màn hình, hầu hết các app sẽ có độ sâu phần cấp là 5, ứng dụng Fueling sẽ có độ sâu là 3, ứng dụng Driving task và Quick food ordering có độ sâu là 2. Tính từ màn hình root.
    Ví dụ: khi xây dựng CP Audio các bạn không thể di chuyển quá 5 màn hình
    Template1 -> Template2 -> Template3 -> Template4 -> Template5 -> Template6
    Di chuyển từ Template1 đến Template5 thì không sao, và app sẽ crash khi di chuyển từ Template5 đến Template6

Hướng dẫn khi xây dựng ứng dụng CP

Khi xây dựng một ứng dụng CP thì chúng ta phải tuân thủ theo 8 hướng chung sau đây: (Mình sẽ lấy nguyên các hướng dẫn của Apple cung cấp để cho các bạn tham khảo nhé)

  1. Your CarPlay app must be designed primarily to provide the specified feature to a user (e.g. CarPlay audio apps must be designed primarily to provide audio playback services, CarPlay parking apps must be designed primarily to provide parking services, etc.).
  2. Never instruct users to pick up their iPhone to perform a task. If there is an error condition, such as a required log in, you can let users know about the condition so they can take action when safe. However, user messages must not include wording that asks users to manipulate their iPhone.
  3. All CarPlay user flows must be possible without interacting with iPhone.
  4. All CarPlay user flows must be meaningful to use while driving. Don’t include features in CarPlay that aren’t related to the primary task (e.g. unrelated settings, maintenance features, etc.).
  5. No gaming or social networking.
  6. Never show the content of messages, texts, or emails on the CarPlay screen.
  7. Use templates for their intended purpose, and only populate templates with the specified information types (e.g. a list template must be used to present a list for selection, album artwork in the now playing screen must be used to show an album cover, etc.).
  8. All voice interaction must be handled using SiriKit (with the exception of CarPlay navigation apps, see below).

Ngoài 8 hướng dẫn chung này ra thì một số CP types có các hướng dẫn đặc biệt nữa. Chúng ta có thể tham khảo ở page 6, 7, 8, 9, 10

Môi trường phát triển

Cũng như các ứng dụng trên iPhone khi các bạn muốn chạy trên device thật thì cần certificate và provisioning. Thì ứng dụng CP cũng vậy. Tuy nhiên khi chạy ứng dụng ra simulator thì không cần thiết.
Ví dụ: Khi xây dựng một ứng dụng hỗ trợ notification thì cần enable notification ở capabilities, thì với ứng dụng CP cũng cần enable entitlement ở trong Additional Capabilities.

Mục Additional Capabilities của tất cả các Apple Account đều là rỗng, developer phải request đến Apple và đợi họ approve thì mới có thể enable Capabilities để chạy trên device thật.

Account của mình đã được Apple approve với type Audio, mình nhớ là mất khoảng 14 ngày để Apple approve.

Đây là Link request nhé!

CP Simulator

Apple cung cấp cho chúng ta hai simulators để thực hiện test trong quá trình phát triển ứng dụng CP

  • xCode Simulator: đây là simulator tích hợp sẵn trong xCode. Chúng ta có thể mở simulator này lên bằng cách chọn I/O -> External Display -> CarPlay…
  • CP Simulator: đây là một tool riêng biệt, nó mô phỏng lại môi trường của xe ô tô và phải cài ứng dụng hỗ trợ CP lên iPhone, sau đó kết nối với máy tính và mở CP Simulator lên (sau khi tải tool về thì mở folder Hardware -> CarPlay Simulator), tất cả các apps hỗ trợ CP trên iPhone sẽ hiển thị trên CP simulator.
    Link tải tool đây nhé, lưu ý các bạn chọn đúng tool mà xCode của mình đang sử dụng nhé

Trên đây là phần giới thiệu của mình về CP, phần tiếp theo mình sẽ chia sẻ việc implement một ứng dụng hỗ trợ CP.

Mình hi vọng bài viết có thể giúp ích được cho các bạn. Chúc các bạn thành công!

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.