windows api 实现 hbitmap avi_【API】多设备OS如何组织SDK API?

背景:

个人使用的设备越来越多,处了手机之外,使用的设备包括IOT,穿戴式(手表),PAD,TV,HandBook等。应用开发者需要为各种各样的设备开发程序。对于OS操作系统厂家来说,提供一套统一的API或者一种清晰组织的API非常重要。我们调查一下IOS,Android,Windows是如何组织API,供大家开发多设备应用程序的。

分析:

1,IOS/TvOs/iPadOS/WatchOS/MacOS

苹果根据不同的设备类型,从品牌上对OS进行区分。目前对外的OS名称包括iPhoneOs,TvOs,IPadOs,WatchOS,MacOs。具体这些OS在技术实现上差异有多大,不得而知。

  • iPadOS is the operating system specifically designed to take full advantage of everything that makes iPad iPad.
  • TvOS:Leverage many of the same frameworks, technologies, and concepts that are similar to iOS. TVMLKit templates using XML and Javascript are available as a framework for tvOS apps that let you use predefined layouts and Javascript APIs to quickly create beautiful apps ideal for streaming media.
  • iOS(formerlyiPhone OS): including theiPhone, andiPod Touch;
  • watchOS:based on iOS, the operating system of theiPhone, and has many similar features

我目前还没有理解背后区分OS品牌的逻辑,但是苹果为开发者提供的SDK API仍旧是统一组织的。

Apple Developer Documentation​developer.apple.com
  • 针对每个OS都有的API(例如UIKit,SwiftUI)会在右侧展示可以使用的IOS版本

06ad39e40496a068b5ab9f9165fa089a.png
  • 针对差异化的API不同部分,会在Kit名字上命名区分:

例如TVUIKit,WatchKit进行区分。

对于Apple API开发人员来说,他们是如何定义API区别不同的OS的?

Mark Availability:

  • ObjectC:API_AVAILABLE(ios(11), macosx(10.13))
  • Swift: available(iOS 11, macOS 10.13, *)

Check Availability

Use the @available() keyword to check availability information in a conditional statement in Objective-C

Marking API Availability in Objective-C​developer.apple.com

2,Windows 10/Universal Windows Platform (UWP) app

windows10操作系统是多设备操作系统(a desktop PC, Xbox, Mixed-reality headset)

d3915987e12a1da56225bf4e4991815f.png

编程API分为两个部分:Universal Device Family APIs和Extension SDKs APIS。例如如果你的应用只应用于IOT设备,你可以导入IoT extension SDK。

706cae6bd74f7a5753de1af92f45d238.png

1,Universal device family API contracts

These API contracts are implemented by all Windows 10 operating system editions.

Universal device family API contracts - Windows UWP applications​docs.microsoft.com
7f057ee4276c1109f99f956ed8e5afbb.png

2,Extension SDKS API

例如Mobile扩展SDK

Windows Mobile Extension SDK API contracts for UWP - Windows UWP applications​docs.microsoft.com
7f057ee4276c1109f99f956ed8e5afbb.png

微软通过这种分层组织API方式可以获取如下好处:

  1. 对于希望部署尽可能的设备上,只允许调用Universal Device API
  2. 对于只允许在单个设备上的应用,可以调用Extension API
  3. 提供机制,可以Writing adaptive code with the Api Information class
    bool isWindows_Devices_Scanners_ScannerDeviceContract_1_0Present =
        Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent
            ("Windows.Devices.Scanners.ScannerDeviceContract", 1, 0);

3,Android,Wear OS、Android TV、Android Auto,CHROME

对于我们来说,Android是比较熟悉的,Android目前应用设备包括手机,TV,手表等。Android本身为了支持多设备编程也做了不少事情,基本思路跟IOS,微软也是类似的,都有一个适合所有的设备的基础API框架集+扩展API框架集。

  • 基础API集合

Android Platform API,AndroidX,

  • 设备类特殊API

androidx.leanback:Android TV

androidx.wear: Android Wear

android.car: Android Auto

  • Android 提供的适配多设备UI适配机制

布局应该从容应对不同的屏幕尺寸和方向,而不是为布局定义刚性尺寸,假定屏幕尺寸和宽高比是一定的。

https://developer.android.com/training/multiscreen/screensizes​developer.android.com
  • 应用商店支持为每个不同的设备发布不同的APP的能力
https://developer.android.com/google/play/publishing/multiple-apks​developer.android.com

4,AliOS

AliOS为多端而生,结合云的能力,实现云端一体化、智能化。支持车机类(Automotive)、电视类(TV)、平板类(Tablet)以及轻量化设备类(Lite)等几类

5861f2e4926be0961b3ec94604d54da8.png

c9f43c259b09ff3a3031de4b00a40216.png

其为开发者提供的API按照设备类别进行分类。API Level 是对 AliOS 操作系统平台所提供的应用开发框架(Cloud Application Framework,简称CAF)API 的唯一自然数版本标识。API Level 机制严格遵循“向后兼容”原则,即 API Level n(其中 n 是自然数)可以确保完全兼容 API Level 1 至 API Level n-1。

结论:

1,采用基础API + 设备类API的方式组织,相对比较清晰,但是按照设备扩展性后续值得讨论。设备类API通过Kit名称/包名的方式区分,如Apple,微软,Android等。

2,在多设备OS下API本身附带了一些单机OS不具备的属性,是否在API定义的时候显式指定适配的属性,如苹果引入annotation方式进行说明。如Java中引入annotation标记API使用的<设备,OS,编程语言>

针对多设备OS,如何组织API,大家有什么好的意见。

参考:

iPadOS​www.apple.com
089498e782319c7b8ed29856dbb33fa6.png
tvOS - Apple Developer​developer.apple.com https://swift.org/documentation/api-design-guidelines/​swift.org How (Not) to Write an iOS SDK​academy.realm.io
ce3fbf19c9a33cc074093e76b97c3a05.png
The Swift Programming Language​docs.swift.org What's a Universal Windows Platform (UWP) app? - UWP applications​docs.microsoft.com
7f057ee4276c1109f99f956ed8e5afbb.png
Device families overview - Windows UWP applications​docs.microsoft.com
7f057ee4276c1109f99f956ed8e5afbb.png
Device families overview - Windows UWP applications​docs.microsoft.com
7f057ee4276c1109f99f956ed8e5afbb.png
developer​developer.alios.cn
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值