Git Product home page Git Product logo

miot-plugin-sdk's Introduction

MIOT SDK for React Native

运行前请先执行npm install

请使用底下提供的测试包调试,不要使用线上包调试

初始化

1, 下载开发环境, 执行 git clone [email protected]:MiEcosystem/miot-plugin-sdk.git

2, 命令行进入开发环境根目录, 安装 node 和 npm, 版本9.0+ ( **推荐mac上:npm版本6.12.1,node版本v12.13.1** )
   内置一键安装开发环境脚本
   Windows: 执行 `bin/install_mihome_dev.bat` (注意按提示关闭实时安全防护)
   MacOS: 执行 `bin/install_mihome_dev.sh`

3, 安装ReactNative基础库, 在根目录下执行 npm install

!注意, 项目中如果需要使用第三方库(仅限于纯js实现), 请进入项目目录(如 projects/com.xiaomi.demo),
执行 npm install --save xxxx, 否则在打包发布时将因为找不到第三方库而失败

命令

创建项目
npm run create xxx.yyy.zzz
    注: xxx.yyy.zzz 为项目路径名, 创建后项目位于projects/xxx.yyy.zzz下
也可以使用米家开发好的模板
npm run create xxx.xxx.xxx[插件包名] -type empty :  创建一个空项目   
npm run create xxx.xxx.xxx[插件包名] -type common : 创建一个通用模板项目(包括: 页面跳转(NavigationBar)、设置页(CommonSetting)、多语言、隐私、自定义场景、固件升级)    
npm run create xxx.xxx.xxx[插件包名] -type wifi :   创建一个wifi模板项目(包括: 通用模板功能、设备控制及属性订阅功能)    
npm run create xxx.xxx.xxx[插件包名] -type ble :    创建一个ble模板项目(包括: 通用模板功能、蓝牙连接相关功能)    

启动调试
npm start xxx.yyy.zzz,使用米家APP扫描控制台中的二维码开启调试。

运行Demo
在/miot-workspace下,执行
    npm install
如果windows 下 fsevents报错,可忽略。mac下,可执行npm install fsevents@latest。
其他报错,请查看issues,或者提工单。然后
    cd projects/com.xiaomi.demo
    npm install
然后就可以npm start,开始调试demo了

**注意:之所以需要在com.xiaomi.demo下再执行一次npm install,是因为我们在com.xiao.demo引入了纯js的第三方库:react-native-root-toast。作为第三方库引入的示例!如果不执行npm install,直接调试com.xiaomi.demo会报错找不到react-native-root-toast!**

发布项目
npm run publish xxx.yyy.zzz
    注: 缺省的目标文件位于 projects/xxx.yyy.zzz/build/publish.mpkg, 可以通过 --target 指定任意目标文件

配置

在项目创建后(如xxx.yyy.zzz), 在projects/xxx.yyy.zzz 目录下有项目配置文件 project.json, 结构说明如下:

{
    "package_path":"xxx.yyy.zzz",     //项目路径名
    "min_sdk_api_level":10000        //支持运行的SDK API_LEVEL
}

注意

1, 不允许对根目录下的 package.json 文件做任何修改,否则将导致在线打包失败,
2, 只允许在各自项目目录下(projects/xxx.yyy.zzz)引用第三方库, 修改这下面的 package.json, 执行 npm install
3, 不允许引用 projects 下其他项目的任何内容

文档

🎉 UI组件说明文档正式公开

正式版,仅包括已经发布的组件

预览版,包括已经发布的组件和开发完成待发布的组件

插件开发请参考《MIOT SDK API》 《CHANGELOG》

插件从RN54版本升至61版本请参考《升级指南》

插件从旧框架迁移到新框架请参考《迁移手册》

插件调试流程请参考《调试说明》

调试环境

iOS IPA 包下载二维码 mihome

Android APK 包下载地址:http://d.maps9.com/MiHomeForAndroid

下载密码: keliyuan

调试包若无法下载,请提交工单。

其他文档

字体使用

miot-plugin-sdk's People

Contributors

blockdate avatar cfjand avatar dependabot[bot] avatar dingsongwenxm avatar fishle avatar kunkaka219 avatar kyou avatar laohuang88 avatar like001 avatar liuhaojie19 avatar liumengzhou avatar lvjie0519 avatar lyuw819 avatar mi-zaz avatar miotplugin avatar pencilcool avatar santcool avatar santcool-1 avatar tanteichang avatar woody2016 avatar xmtc-miot avatar zanetti4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

miot-plugin-sdk's Issues

iphone XR/XS/XS MAX等机型适配问题

用iPhoneX跑了下提供的demo,发现iPhoneX的适配有些问题,状态栏显示一条黑色。查看了TitleBarBlack、TitleBarWhite的适配方式,似乎就是这个效果。
目前是不是还需要判断iPhoneX机型做另外的适配?
wechatimg434

callSmartHomeAPI接口废弃后,KV(Key Value)相关method新SDK中没有找到相对应接口

之前miot后台的同学帮助开发了KV的相关接口(该接口按照key value键值对方式来存储我们插件相关数据)。现在callSmartHomeAPI接口废弃后,新SDK文档中暂未找到与KV接口相关的内容。https://github.com/MiEcosystem/ios-rn-sdk/blob/2dd6a6a243467a0fa84ded5443cd00f6c0f59097/MiHomePluginSDK/docs/callSmartHomeAPI.md 旧SDK中也未有KV的描述,该接口相关文档是由miot同学线下给的,有问题请向miot后台的王松同学咨询。

关于创建项目的包名问题

我看创建项目的时候,会使用我们在小米申请的包名,但是我们的安卓和iOS端的包名不一样,应该使用哪一个包名进行创建呢?

Service.smarthome. setDeviceData问题

Service.smarthome. setDeviceData(did, uid, type, key, time, value),如果我的数据是一个数组怎么办?

以前是数组中每个value都拼装一个{did: "did", uid: "uid", type: "type", key: "key", time: "time", value: ar r[0]},现在接口怎么上传数组?

"miot"的Host模块缺少部分米家公共页面接口

现在缺少以下三个公共页面接口:
1、更多设置。MHPluginSDK.openNewMorePage();
2、定时开关。MHPluginSDK.openTimerSettingPage(onMethod, onParam, offMethod, offParam);
3、管理灯组。MHPluginSDK.openEditDeviceGroupPage(dids);
请在"miot"的Host模块中提供以上三个接口。或者有什么别的开发安排,麻烦也说明一下吧。

如何检测蓝牙开关状态?

1、Device.bluetooth.isEnabled 返回是 undefined,但手机的蓝牙是打开着的
2、BluetoothEvent收不到监听回调

const subscription2 = BluetoothEvent.bluetoothStatusChanged.addListener((bluetooth, isEnabled)=>{
console.log('----------BluetoothEvent 11111 ');
});

miot/service/storage接口相关问题

miot/service/storage接口有以下两个疑问:
1、接口返回数据类型是什么呢?文档中没有说明;
2、文档中描述“MIOT 云端提供的各种暂存服务”,暂存服务是什么意思?是暂时保存么?有时效性么?
3、文档中描述的参数componentId是什么意思呢?

如何获取本地资源目录的路径

RT,本地图片需要动态获取,而require不支持变量,请问如何获取资源目录的 路径?
比如 需要 for 循环 一组图片,需要一个个 require 写?因为require不支持变量

使用RN的WebView报错(iOS)看这里

原因

iOS native 端修改了WebView,增加了新的属性onScrollChange

解决办法

下载fixed中的WebView.ios.js,替换本地项目路径下的node_modules/react-native/Libraries/Components/WebView/WebView.ios.js

Animated.ImageBackground undefined疑惑

“迁移手册”中提到:
https://github.com/MiEcosystem/miot-plugin-sdk/blob/master/%E8%BF%81%E7%A7%BB%E6%89%8B%E5%86%8C.md

<Animated.ImageBackground>
<Animated.Text></Animated.Text>
</Animated.ImageBackground>

但查询到 https://github.com/facebook/react-native/issues/16939
Animated.ImageBackground 其实是undefined的,无法使用,请问是米家内部支持了Animated.ImageBackground么?现在就是需要用这个组件,但插件里面运行奔溃

关于deviceStatusChanged事件问题

该事件deviceStatusChanged可以指定要监听的设备property么?类似旧SDK的设计。https://github.com/MiEcosystem/ios-rn-sdk/blob/c72038bd70f8cbbd7935abf420fb123dc87893d9/MiHomePluginSDK/docs/MHPluginSDK.md

// 假设采用订阅方式,需在 key 之前加前缀,属性为 prop.xxx, 事件为 event.xxx
MHPluginSDK.registerDeviceStatusProps(["prop.rgb","prop.power","event.isOn"]);

// 若采用轮询方法,则无**询事件,只能查询 prop,直接填入 key
// MHPluginSDK.registerDeviceStatusProps(["rgb","power"]);

// 记得初始化 DeviceEventEmitter
const {DeviceEventEmitter} = require('react-native');
// 监听
let subscription = DeviceEventEmitter.addListener(MHPluginSDK.deviceStatusUpdatedEventName,(notification) => {

// 从device属性的内存缓存中拿到轮询的状态结果,同样,订阅需要添加前缀,轮询不用
MHPluginSDK.getDevicePropertyFromMemCache(["prop.rgb","prop.power","event.isOn"], (result) => {
console.log(result);
});

});

获取手机系统相关API

产品中会优先支持MIUI9以上的小米手机,需要判断当然手机的系统信息。在《MIOT SDK API》中并没有找到相关的API,希望提供支持。

关于CommonModules问题

hi,发现项目中已经没有demo了。文档中没有对CommonModules未来支持情况作相关描述,这个框架还要保存么还是废弃了呢?如果要保存的话,目前在该项目中找不到该框架,之前是在demo里面的。

PackageEvent.packageAuthorizationCancel 收不到这个通知

1、openPrivacyLicense进行软件政策和隐私协议授权;
2、privacyAndProtocolReview打开软件政策和隐私协议页面,取消授权;
3、在MainPage.js里的componentDidMount监听packageAuthorizationCancel消息,收不到这个消息

代码:
import {PackageEvent} from 'miot';
.....
const subscription = PackageEvent.packageAuthorizationCancel.addListener(()=>{
alert(222222);
})

国际化语言问题

本地化字符串
const Basic = res.createI18n({
en:{
//英文
tip_bluetoothNotOpen: "Bluetooth is off",
tip_networkError: "Check your network connection and try again",
alert_title_attention: "Attention",
},
zh:{
//简体中文
tip_bluetoothNotOpen: "蓝牙未打开",
tip_networkError: "网络异常,请检查网络后重试",
alert_title_attention: "提醒",
},
});

然后我米家APP语言设置为简体中文,执行代码
console.log("测试语言显示:" + Basic.strings.tip_bluetoothNotOpen);

还是输出的英文字符。帮我看一下,是不是我哪里写错了?

bluetooth.connect(-1) 返回错误

bluetooth.connect(-1).then((data) => { MYLOG("连接成功"); }).catch((data) => { MYLOG(("连接失败:"+data)); });
返回错误如下: "code":"ECOM.XIAOMI.BLELOGIN0"

{"code":"ECOM.XIAOMI.BLELOGIN0","nativeStackIOS":["0 MiHome 0x000000010592af84 RCTFBQuickPerformanceLoggerConfigureHooks + 737468","1 MiHome 0x000000010592aee8 RCTFBQuickPerformanceLoggerConfigureHooks + 737312","2 MiHome 0x0000000105814128 __cxa_throw + 5594304","3 MiHome 0x0000000105682784 __cxa_throw + 3949340","4 MiHome 0x0000000105688604 __cxa_throw + 3973532","5 MiHome 0x00000001056e4ce0 __cxa_throw + 4352120","6 MiHome 0x00000001056a8aa0 __cxa_throw + 4105784","7 libdispatch.dylib 0x000000019a5c96c8 + 24","8 libdispatch.dylib 0x000000019a5ca484 + 16","9 libdispatch.dylib 0x000000019a5769b4 + 1068","10 CoreFoundation 0x000000019ab1f<…>

帮忙看下这个问题怎么解决

另外,麻烦再详细解答下:

type android插件链接蓝牙类型 -1 自动判断,0 小米蓝牙协议设备,1 自己的安全芯片设备,2 分享的安全芯片设备,3 普通的蓝牙协议

我们的蓝牙是小米蓝牙模组,但协议是自定义的,那么应该选 1还是3?
以及 2 是用户分享过来的设备连接?

插件第一个页面自定义导航栏

第一个页面,使用自定义导航栏方式:

export default class MainPage extends React.Component {

    static navigationOptions = ({ navigation }) => {        
        return {
            header: null
        };
    };
   render() {
     return <自定义View>
    }
}
// index.js
const RootStack = createStackNavigator (
  {
    MainPage:MainPage,
  },
  {
    initialRouteName: 'MainPage',
    navigationOptions: ({ navigation }) => {
      return {
        header: <TitleBarWhite title={'common'} style={{ backgroundColor: '#ff0' }}
          onPressLeft={() => {
            if (navigation.routeName == 'MainPage') {
              Package.exit();
            }else{
              navigation.goback();
            }
          }} />,
      };
    },
    transitionConfig: () => ({
      screenInterpolator: CardStackStyleInterpolator.forHorizontal,
    }),
  },
);

之后使用Reveal查看布局结构,顶部导航栏位置会出现一条白色视图,区域为 [-windowSize.width ~ windowSize.width ,导致在退出插件时,会看到 [-windowSize.width ~ 0] 区域的这块白色条

b0fe0e23-749e-41ba-8568-7b2746a91b74

麻烦帮忙看下这是什么问题?
或者说 自定义导航栏后,还要不要设置隐藏导航栏之类的代码?

WebView 问题

import { WebView } from 'react-native';

使用 RN 自带的 WebView 在 iOS 下会导致插件崩溃。
img_a10fe240440f-1

提示Did you run react-native link?

安卓跑官方Demo,结果爆红提示:Something went wrong initializing the native ReactLocalization module.
Please check your configuration.
Did you run 'react-native link'?该打印位于LocalizeStrings.js文件中

关于MHPluginFS模块兼容问题

请问host/storage兼容MHPluginFS该模块么?因为host/storage文档描述的是轻量级存储服务,所以想确认一下是否也兼容MHPluginFS。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.