HarmonyOS鸿蒙Next中RN如何跳转到应用市场?

HarmonyOS鸿蒙Next中RN如何跳转到应用市场?

let url = 'market://details?id=com.cu
if (Platform.OS === 'ios') {
  url = 'itms-apps://itunes.apple.com/app/id153?action=write-review';
} else if (Platform.OS === 'harmony') {
  url = 'store://appgallery.huawei.com/app/detail?id=691756038
}
Linking.canOpenURL(url) // 
  .then(supported => {
    if (!supported) {
      return store.dispatch(
        showAlert({
          title: '暂不支持跳转应用市场',
        }),
      );
    }
    return Linking.openURL(url);
  })

这么试了没反应


更多关于HarmonyOS鸿蒙Next中RN如何跳转到应用市场?的实战教程也可以访问 https://www.itying.com/category-93-b0.html

5 回复

你好,有两种实现方案。

方案1:使用RN自带Deep Links能力。

import React from "react";
import { View, Linking, Button, StyleSheet } from "react-native";

export default function App() {
  return (
    <View style={styles.container}>
      <Button
        title="跳转应用市场"
        onPress={() => {
          // 重要 id是bundleName或者C开头+appID
          // 'store://appgallery.huawei.com/app/detail?id=' + bundleName
          Linking.openURL('https://appgallery.huawei.com/app/detail?id=com.huawei.hmsapp.appgallery')
        }}>
      </Button>
    </View>
  )
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
  },
});

方案2:使用RN TurboModule能力调用HarmonyOS App Linking跳转应用市场。

TurboModule引入方法参考:HarmonyOS RN自定义TurboModule

HarmonyOS跳转应用市场方法实现:

jumpToMarket() {
  const want: Want = {
    uri: `https://appgallery.huawei.com/app/detail?id=com.huawei.hmsapp.appgallery`
  };
  const context = getContext(this) as common.UIAbilityContext;
  context.startAbility(want).then(()=>{
    // 拉起成功
  }).catch(()=>{
    // 拉起失败
  });
}

更多关于HarmonyOS鸿蒙Next中RN如何跳转到应用市场?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


开发者您好,关于您咨询的问题,您可参考App Linking看看能否解决问题,或者提供一下可以复现的demo我们这边定位一下问题。

这个问题跟你说的App Linking不是一个东西。
我想问的是React-Native开发的app怎么跳转到应用市场,在Android能识别market://或ios里识别itms-apps://

你好,内部处理中,请耐心等待。

在HarmonyOS鸿蒙Next中,React Native(RN)应用可以通过调用系统能力实现跳转到应用市场。具体步骤如下:

  1. 导入模块:使用@ohos.app.ability.common模块中的startAbility方法。
  2. 配置Ability:在config.json中声明ohos.permission.INSTALL_BUNDLE权限。
  3. 调用方法:通过startAbility方法启动应用市场的Ability,传递应用包名等参数。

示例代码:

import ability from '@ohos.app.ability.common';

const marketAbility = {
  bundleName: 'com.huawei.appmarket',
  abilityName: 'com.huawei.appmarket.MainAbility'
};

ability.startAbility(marketAbility).then(() => {
  console.log('跳转成功');
}).catch(err => {
  console.error('跳转失败', err);
});

确保设备已安装应用市场,并处理可能的异常情况。

回到顶部