Page 1 of 1

关于在IOS 真机与线上版本问题

Posted: 2023年 May 9日 10:12
by 幽冥墨

主要问题是 @ray-js/panel-sdk 中 new SmartDeviceModel<SmartDeviceSchema>() 中 onInitialized() 函数在Android 上面所有环境使用正常,IOS 上体验本与线上版本不能正常使用,但是开发者工具上与真机调试时表现正常

Code: Select all

********* devices *************

import { SmartDeviceModel } from '@ray-js/panel-sdk';
import { SmartDeviceSchema } from '../../typings/sdm';

export const devices = {
  lamp: new SmartDeviceModel<SmartDeviceSchema>(),
};

Object.keys(devices).forEach((k: keyof typeof devices) => {
  devices[k].init();
  
[b]---------------------------------------------------------------------[/b] ******** typings > sdm ******************** import { ProductName } from '@/constants'; type SmartDeviceSchema = typeof import('@/devices/schema').socketSchema; type SmartDevices = { socket?: import('@tuya-miniapp/sdm').SmartDeviceModel<SmartDeviceSchema>; }; declare module '@ray-js/sdm-react' { export const SdmProvider: React.FC<{ value: SmartDeviceModel<SmartDeviceSchema>; children: React.ReactNode; }>; export type SmartDeviceInstanceData = { devInfo: ReturnType<SmartDevices[ProductName]['getDevInfo']>; dpSchema: ReturnType<SmartDevices[ProductName]['getDpSchema']>; network: ReturnType<SmartDevices[ProductName]['getNetwork']>; bluetooth: ReturnType<SmartDevices[ProductName]['getBluetooth']>; }; export function useProps(): SmartDevices[ProductName]['model']['props']; export function useProps<Value extends any>( selector: (props?: SmartDevices[ProductName]['model']['props']) => Value, equalityFn?: (a: Value, b: Value) => boolean ): Value; export function useDevice(): SmartDeviceInstanceData; export function useDevice<Device extends any>( selector: (device: SmartDeviceInstanceData) => Device, equalityFn?: (a: Device, b: Device) => boolean ): Device; export function useActions(): SmartDevices[ProductName]['model']['actions']; } ----------------------------------------------------------------------------------------------------------------------- **************** 调用文件 *************** import { devices } from '@/devices'; class App extends React.Component<Props> { async onLaunch() { console.log('进入函数体 onLaunch'); console.log('查看这个数据对象类型', devices.lamp.onInitialized(res => { console.log('相同函数怎么会有不同的运行结果呢???*************'); return res })); devices.lamp.onInitialized(res => { console.log('进入 onInitialized 函数体'); }) } }); [b]Android 调用结果[/b] [attachment=2]android_bug.jpg[/attachment] [b]IOS 调用结果[/b] [attachment=1]IOS_bug.jpg[/attachment] [b]IOS 版本信息[/b] [attachment=0]IOS_info.jpg[/attachment]

Re: 关于在IOS 真机与线上版本问题

Posted: 2023年 May 9日 17:08
by 幽冥墨

将 onInitialized 函数提取到 App 函数体外面就可以正常运行,目前测试是没有什么问题


Re: 关于在IOS 真机与线上版本问题

Posted: 2023年 Aug 18日 13:59
by lshinylee

为避免出现类似问题,我们优化了一下模板,https://github.com/Tuya-Community/tuya-ray-demo/pull/20