{"_id":"@bbhxwl/jpush-expo-plugin","name":"@bbhxwl/jpush-expo-plugin","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@bbhxwl/jpush-expo-plugin","version":"1.0.0","description":"Expo config plugin for JPush (极光推送) - Compatible with Expo SDK 54+","main":"build/index.js","types":"build/index.d.ts","scripts":{"build":"tsc","clean":"rm -rf build","prepare":"npm run clean && npm run build","prepublishOnly":"npm run build"},"keywords":["expo","expo-plugin","config-plugin","jpush","push-notification","react-native","jiguang","极光推送"],"author":{"name":"xuzhibin"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/bbhxwl/jpush-expo-plugin.git"},"bugs":{"url":"https://github.com/bbhxwl/jpush-expo-plugin/issues"},"peerDependencies":{"expo":">=49.0.0"},"devDependencies":{"@expo/config-plugins":"^9.0.0","@types/node":"^20.0.0","typescript":"^5.0.0"},"_id":"@bbhxwl/jpush-expo-plugin@1.0.0","gitHead":"dc68142f4b920767a8dc74a10d03ede0c74ff95b","homepage":"https://github.com/bbhxwl/jpush-expo-plugin#readme","_nodeVersion":"20.20.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-idpPvqbYq9cNGSvd/NwNvHy3va/Ti/t1e4hQht/qK9InI542Ew6RSzH/EdmvOjadidGUKsFnPLMewBhBmI8b9Q==","shasum":"da5a40ff6a1ceab203e275af41f4f25dcf3cf9cc","tarball":"https://registry.npmjs.org/@bbhxwl/jpush-expo-plugin/-/jpush-expo-plugin-1.0.0.tgz","fileCount":6,"unpackedSize":32362,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD4bIMq5yQZ68Kqa1EYWc4sBMnoE55MUwCwjVgwomtFaQIhANHcqAhutmJU07vMbSnA0zwUbcxPMyQ45hXGIdcq4vjo"}]},"_npmUser":{"name":"bbhxwl","email":"470138890@qq.com"},"directories":{},"maintainers":[{"name":"bbhxwl","email":"470138890@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jpush-expo-plugin_1.0.0_1769260982871_0.7322430063018592"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-24T13:23:02.811Z","1.0.0":"2026-01-24T13:23:03.014Z","modified":"2026-01-24T13:23:03.215Z"},"maintainers":[{"name":"bbhxwl","email":"470138890@qq.com"}],"description":"Expo config plugin for JPush (极光推送) - Compatible with Expo SDK 54+","homepage":"https://github.com/bbhxwl/jpush-expo-plugin#readme","keywords":["expo","expo-plugin","config-plugin","jpush","push-notification","react-native","jiguang","极光推送"],"repository":{"type":"git","url":"git+https://github.com/bbhxwl/jpush-expo-plugin.git"},"author":{"name":"xuzhibin"},"bugs":{"url":"https://github.com/bbhxwl/jpush-expo-plugin/issues"},"license":"MIT","readme":"# jpush-expo-plugin\n\n极光推送 (JPush) Expo 配置插件，兼容 Expo SDK 49+。\n\n## 安装\n\n```bash\n# 使用 npm\nnpm install jpush-expo-plugin jpush-react-native jcore-react-native\n\n# 使用 yarn\nyarn add jpush-expo-plugin jpush-react-native jcore-react-native\n\n# 使用 pnpm\npnpm add jpush-expo-plugin jpush-react-native jcore-react-native\n```\n\n## 配置\n\n### 1. 添加插件配置\n\n在 `app.json` 或 `app.config.js` 中添加插件：\n\n**app.json**\n\n```json\n{\n  \"expo\": {\n    \"plugins\": [\n      [\n        \"jpush-expo-plugin\",\n        {\n          \"appKey\": \"你的极光AppKey\",\n          \"channel\": \"developer-default\"\n        }\n      ]\n    ]\n  }\n}\n```\n\n**app.config.js / app.config.ts**\n\n```js\nexport default {\n  expo: {\n    plugins: [\n      [\n        'jpush-expo-plugin',\n        {\n          appKey: '你的极光AppKey',\n          channel: 'developer-default',\n          production: false,\n          enableEntitlements: true,\n        },\n      ],\n    ],\n  },\n};\n```\n\n### 2. 生成原生项目\n\n```bash\nnpx expo prebuild\n```\n\n### 3. 运行项目\n\n```bash\n# Android\nnpx expo run:android\n\n# iOS\nnpx expo run:ios\n```\n\n## 插件参数\n\n| 参数 | 类型 | 必填 | 默认值 | 说明 |\n|------|------|------|--------|------|\n| `appKey` | `string` | 是 | - | 极光控制台获取的 AppKey |\n| `channel` | `string` | 是 | - | 渠道名称，用于统计分发渠道 |\n| `production` | `boolean` | 否 | `false` | iOS 是否使用生产环境（App Store 发布时设为 `true`） |\n| `enableEntitlements` | `boolean` | 否 | `true` | iOS 是否自动配置推送权限 |\n\n## 代码中使用\n\n### 基础初始化\n\n```typescript\nimport { useEffect } from 'react';\nimport JPush from 'jpush-react-native';\n\nexport default function App() {\n  useEffect(() => {\n    // 初始化极光推送\n    JPush.init({\n      appKey: '你的极光AppKey',\n      channel: 'developer-default',\n      production: false,\n    });\n\n    // 获取 RegistrationID\n    JPush.getRegistrationID((result) => {\n      console.log('RegistrationID:', result.registerID);\n    });\n  }, []);\n\n  return (\n    // your app\n  );\n}\n```\n\n### 完整示例\n\n```typescript\nimport { useEffect } from 'react';\nimport { Platform } from 'react-native';\nimport JPush from 'jpush-react-native';\n\nexport default function App() {\n  useEffect(() => {\n    initJPush();\n    return () => {\n      // 清理监听器\n      JPush.removeListener();\n    };\n  }, []);\n\n  const initJPush = () => {\n    // 初始化\n    JPush.init({\n      appKey: '你的极光AppKey',\n      channel: 'developer-default',\n      production: false,\n    });\n\n    // 获取 RegistrationID\n    JPush.getRegistrationID((result) => {\n      console.log('RegistrationID:', result.registerID);\n    });\n\n    // 监听收到推送通知\n    JPush.addNotificationListener((notification) => {\n      console.log('收到通知:', notification);\n      // notification 结构:\n      // {\n      //   messageID: string,\n      //   title: string,\n      //   content: string,\n      //   extras: object,\n      //   badge: number (iOS),\n      //   ring: string (Android),\n      //   notificationEventType: 'notificationArrived' | 'notificationOpened'\n      // }\n    });\n\n    // 监听自定义消息\n    JPush.addCustomMessageListener((message) => {\n      console.log('收到自定义消息:', message);\n    });\n\n    // 监听本地通知\n    JPush.addLocalNotificationListener((notification) => {\n      console.log('收到本地通知:', notification);\n    });\n\n    // iOS: 请求通知权限\n    if (Platform.OS === 'ios') {\n      JPush.requestNotificationAuthorization((result) => {\n        console.log('通知权限:', result);\n      });\n    }\n  };\n\n  // 设置别名（用于指定用户推送）\n  const setAlias = (alias: string) => {\n    JPush.setAlias({\n      alias: alias,\n      sequence: Date.now(),\n    });\n  };\n\n  // 删除别名\n  const deleteAlias = () => {\n    JPush.deleteAlias({\n      sequence: Date.now(),\n    });\n  };\n\n  // 设置标签（用于分组推送）\n  const setTags = (tags: string[]) => {\n    JPush.setTags({\n      tags: tags,\n      sequence: Date.now(),\n    });\n  };\n\n  // 添加标签\n  const addTags = (tags: string[]) => {\n    JPush.addTags({\n      tags: tags,\n      sequence: Date.now(),\n    });\n  };\n\n  // 删除标签\n  const deleteTags = (tags: string[]) => {\n    JPush.deleteTags({\n      tags: tags,\n      sequence: Date.now(),\n    });\n  };\n\n  // 清空所有标签\n  const cleanTags = () => {\n    JPush.cleanTags({\n      sequence: Date.now(),\n    });\n  };\n\n  // 设置角标数字 (iOS)\n  const setBadge = (badge: number) => {\n    JPush.setBadge({\n      badge: badge,\n      appBadge: badge,\n    });\n  };\n\n  return (\n    // your app\n  );\n}\n```\n\n### 使用 Hook 封装\n\n```typescript\n// hooks/useJPush.ts\nimport { useEffect, useCallback } from 'react';\nimport { Platform } from 'react-native';\nimport JPush from 'jpush-react-native';\n\ninterface JPushConfig {\n  appKey: string;\n  channel: string;\n  production?: boolean;\n}\n\ninterface NotificationCallback {\n  onNotificationArrived?: (notification: any) => void;\n  onNotificationOpened?: (notification: any) => void;\n  onCustomMessage?: (message: any) => void;\n}\n\nexport function useJPush(config: JPushConfig, callbacks?: NotificationCallback) {\n  useEffect(() => {\n    // 初始化\n    JPush.init({\n      appKey: config.appKey,\n      channel: config.channel,\n      production: config.production ?? false,\n    });\n\n    // 监听通知\n    JPush.addNotificationListener((notification) => {\n      if (notification.notificationEventType === 'notificationArrived') {\n        callbacks?.onNotificationArrived?.(notification);\n      } else if (notification.notificationEventType === 'notificationOpened') {\n        callbacks?.onNotificationOpened?.(notification);\n      }\n    });\n\n    // 监听自定义消息\n    JPush.addCustomMessageListener((message) => {\n      callbacks?.onCustomMessage?.(message);\n    });\n\n    // iOS 请求权限\n    if (Platform.OS === 'ios') {\n      JPush.requestNotificationAuthorization(() => {});\n    }\n\n    return () => {\n      JPush.removeListener();\n    };\n  }, []);\n\n  const setAlias = useCallback((alias: string) => {\n    JPush.setAlias({ alias, sequence: Date.now() });\n  }, []);\n\n  const deleteAlias = useCallback(() => {\n    JPush.deleteAlias({ sequence: Date.now() });\n  }, []);\n\n  const setTags = useCallback((tags: string[]) => {\n    JPush.setTags({ tags, sequence: Date.now() });\n  }, []);\n\n  const getRegistrationID = useCallback(() => {\n    return new Promise<string>((resolve) => {\n      JPush.getRegistrationID((result) => {\n        resolve(result.registerID);\n      });\n    });\n  }, []);\n\n  return {\n    setAlias,\n    deleteAlias,\n    setTags,\n    getRegistrationID,\n  };\n}\n```\n\n使用 Hook:\n\n```typescript\nimport { useJPush } from './hooks/useJPush';\n\nexport default function App() {\n  const { setAlias, setTags, getRegistrationID } = useJPush(\n    {\n      appKey: '你的极光AppKey',\n      channel: 'developer-default',\n      production: false,\n    },\n    {\n      onNotificationArrived: (notification) => {\n        console.log('通知到达:', notification);\n      },\n      onNotificationOpened: (notification) => {\n        console.log('通知被点击:', notification);\n        // 处理通知点击，如跳转页面\n      },\n      onCustomMessage: (message) => {\n        console.log('自定义消息:', message);\n      },\n    }\n  );\n\n  // 登录后设置别名\n  const handleLogin = async (userId: string) => {\n    setAlias(userId);\n  };\n\n  return (\n    // your app\n  );\n}\n```\n\n## 插件配置说明\n\n### Android 配置\n\n插件会自动完成以下配置：\n\n- 添加权限：`POST_NOTIFICATIONS`、`VIBRATE`、`RECEIVE_BOOT_COMPLETED`\n- 在 `AndroidManifest.xml` 中添加 `JPUSH_APPKEY` 和 `JPUSH_CHANNEL`\n- 在 `build.gradle` 中配置 `manifestPlaceholders`\n\n### iOS 配置\n\n插件会自动完成以下配置：\n\n- 在 `Info.plist` 中添加 `remote-notification` 后台模式\n- 在 `Entitlements` 中配置 `aps-environment`（开发/生产）\n\n### iOS 额外步骤\n\n1. 在 [Apple Developer](https://developer.apple.com/) 控制台启用 Push Notifications 功能\n2. 创建并下载 APNs 证书或密钥\n3. 在 [极光控制台](https://www.jiguang.cn/) 上传证书或配置密钥\n4. 发布到 App Store 时，将 `production` 设置为 `true`\n\n## 常见问题\n\n### Q: iOS 收不到推送？\n\n1. 确认已在 Apple Developer 启用推送功能\n2. 确认已上传 APNs 证书到极光控制台\n3. 检查 `production` 参数是否正确（开发用 `false`，生产用 `true`）\n4. 真机测试，模拟器不支持推送\n\n### Q: Android 收不到推送？\n\n1. 确认 `appKey` 和 `channel` 配置正确\n2. 检查是否有厂商通道配置（华为、小米、OPPO 等）\n3. 确认应用未被系统杀死\n\n### Q: 如何获取 RegistrationID？\n\n```typescript\nJPush.getRegistrationID((result) => {\n  console.log('RegistrationID:', result.registerID);\n});\n```\n\n### Q: 如何在 EAS Build 中使用？\n\n正常配置即可，EAS Build 会自动执行 prebuild 并应用插件配置。\n\n```bash\neas build --platform all\n```\n\n## 相关链接\n\n- [极光推送官网](https://www.jiguang.cn/)\n- [极光推送文档](https://docs.jiguang.cn/jpush/guideline/intro)\n- [jpush-react-native](https://github.com/jpush/jpush-react-native)\n- [Expo Config Plugins](https://docs.expo.dev/config-plugins/introduction/)\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-17f5000c657371cf2b2604645a337c84"}