{"id":29547962,"url":"https://github.com/jpush/jpush-harmony-rn-plugin","last_synced_at":"2025-07-17T20:43:39.234Z","repository":{"id":289781431,"uuid":"869302985","full_name":"jpush/jpush-harmony-rn-plugin","owner":"jpush","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-25T01:57:07.000Z","size":117,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-25T02:54:22.738Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jpush.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-08T04:25:47.000Z","updated_at":"2025-04-25T01:57:11.000Z","dependencies_parsed_at":"2025-04-25T03:05:51.063Z","dependency_job_id":null,"html_url":"https://github.com/jpush/jpush-harmony-rn-plugin","commit_stats":null,"previous_names":["jpush/jpush-harmony-rn-plugin"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jpush/jpush-harmony-rn-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpush%2Fjpush-harmony-rn-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpush%2Fjpush-harmony-rn-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpush%2Fjpush-harmony-rn-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpush%2Fjpush-harmony-rn-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jpush","download_url":"https://codeload.github.com/jpush/jpush-harmony-rn-plugin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpush%2Fjpush-harmony-rn-plugin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265660780,"owners_count":23807217,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-17T20:43:35.863Z","updated_at":"2025-07-17T20:43:39.227Z","avatar_url":"https://github.com/jpush.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jpush-harmony-rn-plugin\n\n## 安装方式\n### 手动安装\n\n```\ngit clone https://github.com/jpush/jpush-harmony-rn-plugin  ----下载源码\n\n复制：jpush-harmony-rn-plugin-1.0.0.tgz  到RN项目中\n\n在RN项目中进行引用：\n如：\n \"dependencies\": {\n    ...\n     \"jpush-harmony-rn-plugin\": \"file:./jpush-harmony-rn-plugin-1.0.0.tgz\",\n    ...\n  }\n\nnpm update\n\n\n在项目中使用：\n\nimport { JPushModule } from 'jpush-harmony-rn-plugin';\n\n```\n\n## 方法\n\n|Key | Support | Description |\n| --- | ---- | ----------- |\n|init()         | harmony |init       | \n|setDebug(d: boolean)       | harmony | 设置debug 模式                     |\n|setAppKey(appKey: string)         | harmony |设置极光appkey                             |\n|setChannel(channel: string)         | harmony |设置通知channel                             |\n|getRegistrationId()       | harmony |获取regID                            |\n|setTags(sequence: number, tags: string[]) | harmony |设置tags  |\n|addTags(sequence: number, tags: string[]) | harmony |添加tags  |\n|deleteTags(sequence: number, tags: string[]) | harmony |删除tags  |\n|cleanTags(sequence: number) | harmony |清理tags  |\n|getTags(sequence: number, cur: number) | harmony| 获取tags  |\n|checkTagBindState(sequence: number, tag: string) | harmony| 查验tags绑定状态  |\n|deleteAlias(sequence: number) | harmony |删除alias  |\n|getAlias(sequence: number) | harmony |获取alias  |\n|stopPush() | harmony |停止push  |\n|resumePush() | harmony |恢复Push  |\n|isPushStopped() | harmony |获取Push状态：是否停止  |\n|setBadgeNumber(sequence: number) | harmony| 设置角标  |\n\n具体API请查验极光API [JPush HarmonyOS API](https://docs.jiguang.cn/jpush/client/HarmonyOS/hmos_api)。\n\n## 回调 ---直接复制即可\n\n```\naddListeners() {\n    this.registerListener = DeviceEventEmitter.addListener(\"onRegister\", (data) =\u003e {\n      console.log(\"RN 监听 注册成功:\", data);\n    });\n\n    this.connectedListener = DeviceEventEmitter.addListener(\"onConnected\", (data) =\u003e {\n      console.log(\"RN 监听 连接成功:\", data);\n    });\n\n    this.tagOperatorResultListener = DeviceEventEmitter.addListener(\"onTagOperatorResult\", (data) =\u003e {\n      console.log(\"RN 监听 标签操作结果:\", data);\n    });\n\n    this.aliasOperatorResultListener = DeviceEventEmitter.addListener(\"onAliasOperatorResult\", (data) =\u003e {\n      console.log(\"RN 监听 别名操作结果:\", data);\n    });\n\n    this.clickMessageListener = DeviceEventEmitter.addListener(\"onClickMessage\", (data) =\u003e {\n      console.log(\"RN 监听 点击消息:\", data);\n    });\n\n    this.customMessageListener = DeviceEventEmitter.addListener(\"onCustomMessage\", (data) =\u003e {\n      console.log(\"RN 监听 自定义消息:\", data);\n    });\n\n    this.jMessageExtraListener = DeviceEventEmitter.addListener(\"onJMessageExtra\", (data) =\u003e {\n      console.log(\"RN 监听 JMessage附加数据:\", data);\n    });\n\n    this.jMessageVoIPListener = DeviceEventEmitter.addListener(\"onJMessageVoIP\", (data) =\u003e {\n      console.log(\"RN 监听 JMessage VoIP 数据:\", data);\n    });\n\n    this.commandResultListener = DeviceEventEmitter.addListener(\"onCommandResult\", (data) =\u003e {\n      console.log(\"RN 监听 命令结果:\", data);\n    });\n  }\n```\n\n##  App.tsx 调用示例\n\n```import React from 'react';\nimport {StyleSheet, Text, View, ScrollView,TouchableOpacity,TouchableHighlight,DeviceEventEmitter,EmitterSubscription} from 'react-native';\n\n// import { picker } from 'react-native-picker';\nimport { JPushModule } from 'jpush-harmony-rn-plugin';\nconst styles = StyleSheet.create({\n  scrollView: {\n    flex: 1,\n  },\n  container: {\n      flex: 1,\n      justifyContent: 'center',\n      alignItems: 'center',\n      backgroundColor: '#F5FCFF',\n  },\n  button: {\n      width: 320,\n      justifyContent: 'center',\n      alignItems: 'center',\n      marginTop: 10,\n      borderWidth: 1,\n      borderColor: '#3e83d7',\n      borderRadius: 8,\n      backgroundColor: '#3e83d7',\n      padding: 10\n  },\n  buttonText: {\n      textAlign: 'center',\n      fontSize: 25,\n      color: '#ffffff'\n  }\n});\ninterface AppProps {}\n\n\nexport default class App extends React.Component {\n  registerListener: EmitterSubscription | null = null;\n  connectedListener: EmitterSubscription | null = null;\n  tagOperatorResultListener: EmitterSubscription | null = null;\n  aliasOperatorResultListener: EmitterSubscription | null = null;\n  clickMessageListener: EmitterSubscription | null = null;\n  customMessageListener: EmitterSubscription | null = null;\n  jMessageExtraListener: EmitterSubscription | null = null;\n  jMessageVoIPListener: EmitterSubscription | null = null;\n  commandResultListener: EmitterSubscription | null = null;\n  constructor(props: AppProps) {\n    super(props); // 传递空的 props\n    JPushModule.setAppKey(\"b266cd5c8544ba09b23733e3\");\n    JPushModule.init();\n    JPushModule.setDebug(true);\n    this.addListeners();\n  }\n\n  addListeners() {\n    this.registerListener = DeviceEventEmitter.addListener(\"onRegister\", (data) =\u003e {\n      console.log(\"RN 监听 注册成功:\", data);\n    });\n\n    this.connectedListener = DeviceEventEmitter.addListener(\"onConnected\", (data) =\u003e {\n      console.log(\"RN 监听 连接成功:\", data);\n    });\n\n    this.tagOperatorResultListener = DeviceEventEmitter.addListener(\"onTagOperatorResult\", (data) =\u003e {\n      console.log(\"RN 监听 标签操作结果:\", data);\n    });\n\n    this.aliasOperatorResultListener = DeviceEventEmitter.addListener(\"onAliasOperatorResult\", (data) =\u003e {\n      console.log(\"RN 监听 别名操作结果:\", data);\n    });\n\n    this.clickMessageListener = DeviceEventEmitter.addListener(\"onClickMessage\", (data) =\u003e {\n      console.log(\"RN 监听 点击消息:\", data);\n    });\n\n    this.customMessageListener = DeviceEventEmitter.addListener(\"onCustomMessage\", (data) =\u003e {\n      console.log(\"RN 监听 自定义消息:\", data);\n    });\n\n    this.jMessageExtraListener = DeviceEventEmitter.addListener(\"onJMessageExtra\", (data) =\u003e {\n      console.log(\"RN 监听 JMessage附加数据:\", data);\n    });\n\n    this.jMessageVoIPListener = DeviceEventEmitter.addListener(\"onJMessageVoIP\", (data) =\u003e {\n      console.log(\"RN 监听 JMessage VoIP 数据:\", data);\n    });\n\n    this.commandResultListener = DeviceEventEmitter.addListener(\"onCommandResult\", (data) =\u003e {\n      console.log(\"RN 监听 命令结果:\", data);\n    });\n  }\n\n  componentWillUnmount() {\n    // 移除所有监听器\n    if (this.registerListener) this.registerListener.remove();\n    if (this.connectedListener) this.connectedListener.remove();\n    if (this.tagOperatorResultListener) this.tagOperatorResultListener.remove();\n    if (this.aliasOperatorResultListener) this.aliasOperatorResultListener.remove();\n    if (this.clickMessageListener) this.clickMessageListener.remove();\n    if (this.customMessageListener) this.customMessageListener.remove();\n    if (this.jMessageExtraListener) this.jMessageExtraListener.remove();\n    if (this.jMessageVoIPListener) this.jMessageVoIPListener.remove();\n    if (this.commandResultListener) this.commandResultListener.remove();\n  }\n  handleSetChannel = async () =\u003e {\n    try {\n      await JPushModule.setChannel('your_channel'); // 替换为实际的 channel\n      console.log(\"RN Channel set\");\n    } catch (error) {\n      console.error(\"Error setting channel:\", error);\n    }\n  };\n\n  handleGetRegistrationId = async () =\u003e {\n    try {\n      const registrationId = await JPushModule.getRegistrationId();\n      console.log(\"RN getRegistrationId:\", registrationId);\n    } catch (error) {\n      console.error(\"Error getting registration ID:\", error);\n    }\n  };\n\n  handleSetTags = async () =\u003e {\n    try {\n      await JPushModule.setTags(1, ['tag1', 'tag2']); // 示例标签\n      console.log(\"RN Tags set\");\n    } catch (error) {\n      console.error(\"Error setting tags:\", error);\n    }\n  };\n\n  handleAddTags = async () =\u003e {\n    try {\n      await JPushModule.addTags(1, ['tag3']);\n      console.log(\"RN Tags added\");\n    } catch (error) {\n      console.error(\"Error adding tags:\", error);\n    }\n  };\n\n  handleDeleteTags = async () =\u003e {\n    try {\n      await JPushModule.deleteTags(1, ['tag1']);\n      console.log(\"RN Tags deleted\");\n    } catch (error) {\n      console.error(\"Error deleting tags:\", error);\n    }\n  };\n\n  handleCleanTags = async () =\u003e {\n    try {\n      await JPushModule.cleanTags(1);\n      console.log(\"RN All tags cleaned\");\n    } catch (error) {\n      console.error(\"Error cleaning tags:\", error);\n    }\n  };\n\n  handleGetTags = async () =\u003e {\n    try {\n      await JPushModule.getTags(1, 0); // 示例参数\n      console.log(\"RN Tags retrieved\");\n    } catch (error) {\n      console.error(\"Error getting tags:\", error);\n    }\n  };\n\n  handleCheckTagBindState = async () =\u003e {\n    try {\n      await JPushModule.checkTagBindState(1, 'tag1');\n      console.log(\"RN Tag bind state checked\");\n    } catch (error) {\n      console.error(\"Error checking tag bind state:\", error);\n    }\n  };\n\n  handleSetAlias = async () =\u003e {\n    try {\n      await JPushModule.setAlias(1, 'myAlias');\n      console.log(\"RN Alias set to 'myAlias'\");\n    } catch (error) {\n      console.error(\"Error setting alias:\", error);\n    }\n  };\n\n  handleDeleteAlias = async () =\u003e {\n    try {\n      await JPushModule.deleteAlias(1);\n      console.log(\"RN Alias deleted\");\n    } catch (error) {\n      console.error(\"Error deleting alias:\", error);\n    }\n  };\n\n  handleGetAlias = async () =\u003e {\n    try {\n      const alias = await JPushModule.getAlias(1);\n      console.log(\"RN Alias retrieved:\", alias);\n    } catch (error) {\n      console.error(\"Error getting alias:\", error);\n    }\n  };\n\n  handleStopPush = async () =\u003e {\n    try {\n      await JPushModule.stopPush();\n      console.log(\"RN Push stopped\");\n    } catch (error) {\n      console.error(\"Error stopping push:\", error);\n    }\n  };\n\n  handleResumePush = async () =\u003e {\n    try {\n      await JPushModule.resumePush();\n      console.log(\"RN Push resumed\");\n    } catch (error) {\n      console.error(\"Error resuming push:\", error);\n    }\n  };\n\n  handleCheckPushStatus = () =\u003e {\n    try {\n      const isStopped = JPushModule.isPushStopped();\n      console.log(\"RN Is push stopped?:\", isStopped);\n    } catch (error) {\n      console.error(\"Error checking push status:\", error);\n    }\n  };\n\n  handleSetBadgeNumber = async () =\u003e {\n    try {\n      await JPushModule.setBadgeNumber(1);\n      console.log(\"RN Badge number set\");\n    } catch (error) {\n      console.error(\"Error setting badge number:\", error);\n    }\n  };\n\n  renderButtons() {\n    return (\n      \u003cScrollView style={styles.scrollView}\u003e\n      \u003cView style={styles.container}\u003e\n       \n        \u003cTouchableOpacity style={styles.button} onPress={this.handleSetChannel}\u003e\n          \u003cText style={styles.buttonText}\u003e设置 Channel\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleGetRegistrationId}\u003e\n          \u003cText style={styles.buttonText}\u003e获取注册 ID\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleSetTags}\u003e\n          \u003cText style={styles.buttonText}\u003e设置 Tags\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleAddTags}\u003e\n          \u003cText style={styles.buttonText}\u003e添加 Tags\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleDeleteTags}\u003e\n          \u003cText style={styles.buttonText}\u003e删除 Tags\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleCleanTags}\u003e\n          \u003cText style={styles.buttonText}\u003e清空 Tags\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleGetTags}\u003e\n          \u003cText style={styles.buttonText}\u003e获取 Tags\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleCheckTagBindState}\u003e\n          \u003cText style={styles.buttonText}\u003e检查 Tag 绑定状态\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleSetAlias}\u003e\n          \u003cText style={styles.buttonText}\u003e设置 Alias\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleDeleteAlias}\u003e\n          \u003cText style={styles.buttonText}\u003e删除 Alias\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleGetAlias}\u003e\n          \u003cText style={styles.buttonText}\u003e获取 Alias\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleStopPush}\u003e\n          \u003cText style={styles.buttonText}\u003e停止推送\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleResumePush}\u003e\n          \u003cText style={styles.buttonText}\u003e恢复推送\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleCheckPushStatus}\u003e\n          \u003cText style={styles.buttonText}\u003e检查推送状态\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        \u003cTouchableOpacity style={styles.button} onPress={this.handleSetBadgeNumber}\u003e\n          \u003cText style={styles.buttonText}\u003e设置角标\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n      \u003c/View\u003e\n      \u003c/ScrollView\u003e\n    );\n  }\n  \n\n  render() {\n    return (\n      \u003cView style={styles.container}\u003e\n        {this.renderButtons()}\n      \u003c/View\u003e\n    );\n  }\n}\t\n```\n## 鸿蒙侧集成请查看 [JPush HarmonyOS 集成](https://docs.jiguang.cn/jpush/client/HarmonyOS/hmos_guide)。\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpush%2Fjpush-harmony-rn-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpush%2Fjpush-harmony-rn-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpush%2Fjpush-harmony-rn-plugin/lists"}