
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@ohmi/push-notification-ios
Advanced tools
模板版本:v0.3.0
@ohmi/push-notification-ios
本项目基于 @react-native-community/push-notification-ios@1.11.0 开发。
进入到工程目录并输入以下命令:
npm install @ohmi/push-notification-ios
yarn add @ohmi/push-notification-ios
下面的代码展示了这个库的基本使用场景:
[!WARNING] 使用时 import 的库名不变。
import React, { useState } from "react";
import { View, Text, Button } from "react-native";
import PushNotification from "@react-native-community/push-notification-ios";
export const App = () => {
const [data, setData] = useState({});
const presentLocalNotification = () => {
PushNotification.presentLocalNotification({
id: "test",
title: "title",
subtitle: "subtitle",
body: "body",
repeats: true,
});
};
const addSilentNotificationRequest = () => {
PushNotification.presentLocalNotification({
id: "test-4",
title: "title",
subtitle: "subtitle",
body: "body",
isSilent: true,
repeats: true,
userInfo: {
data: "123456",
},
});
};
const addMultipleRequests = () => {
PushNotification.presentLocalNotification({
id: "test-1",
title: "First",
subtitle: "subtitle",
body: "First Notification out of 3",
repeats: true,
});
PushNotification.presentLocalNotification({
id: "test-2",
title: "Second",
subtitle: "subtitle",
body: "Second Notification out of 3",
repeats: true,
});
PushNotification.presentLocalNotification({
id: "test-3",
title: "Third",
subtitle: "subtitle",
body: "Third Notification out of 3",
repeats: true,
});
};
const removeAllDeliveredNotifications = () => {
PushNotification.removeAllDeliveredNotifications();
};
const removeDeliveredNotifications = () => {
PushNotification.removeDeliveredNotifications(["test-1", "test-2"]);
};
const getDeliveredNotifications = () => {
PushNotification.getDeliveredNotifications((data) => {
if (data) {
setData(data);
} else {
console.log("failed");
}
});
};
return (
<View style={{ flexDirection: "column", justifyContent: "space-between" }}>
<Button
title="Add Notification Request"
onPress={presentLocalNotification}
/>
<Button
title="Add Slient Notification Request"
onPress={addSilentNotificationRequest}
/>
<Button
title="Add Multiple Notification Requests"
onPress={addMultipleRequests}
/>
<Button
title="Set app's icon badge to 42"
onPress={() => PushNotification.setApplicationIconBadgeNumber(42)}
/>
<Button
title="Clear app's icon badge"
onPress={() => PushNotification.setApplicationIconBadgeNumber(0)}
/>
<Button
title="Remove All Delivered Notification Requests"
onPress={removeAllDeliveredNotifications}
/>
<Button
title="Remove Delivered Notification Requests"
onPress={removeDeliveredNotifications}
/>
<View>
<Button
title="Get Delivered Notification"
onPress={getDeliveredNotifications}
/>
<Text>{JSON.stringify(data)}</Text>
</View>
</View>
);
};
此步骤为手动配置原生依赖项的指导。
首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 harmony
。
为了让工程依赖同一个版本的 RN SDK,需要在工程根目录的 oh-package.json5
添加 overrides 字段,指向工程需要使用的 RN SDK 版本。替换的版本既可以是一个具体的版本号,也可以是一个模糊版本,还可以是本地存在的 HAR 包或源码目录。
关于该字段的作用请阅读官方说明
{
"overrides": {
"@rnoh/react-native-openharmony": "^0.72.38" // ohpm 在线版本
// "@rnoh/react-native-openharmony" : "./react_native_openharmony.har" // 指向本地 har 包的路径
// "@rnoh/react-native-openharmony" : "./react_native_openharmony" // 指向源码路径
}
}
目前有两种方法:
方法一:通过 har 包引入(推荐)
[!TIP] har 包位于三方库安装路径的
harmony
文件夹下。
打开 entry/oh-package.json5
,添加以下依赖
"dependencies": {
"@ohmi/push-notification-ios": "file:../../node_modules/@ohmi/push-notification-ios/harmony/push_notification.har"
}
点击右上角的 sync
按钮
或者在命令行终端执行:
cd entry
ohpm install
方法二:直接链接源码
[!TIP] 如需使用直接链接源码,请参考直接链接源码说明
打开 entry/src/main/ets/RNPackagesFactory.ts
,添加:
...
+ import { PushNotificationPackage } from '@ohmi/push-notification-ios/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
return [
new SamplePackage(ctx),
+ new PushNotificationPackage(ctx)
];
}
点击右上角的 sync
按钮
或者在终端执行:
cd entry
ohpm install
然后编译、运行即可。
请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:@ohmi/push-notification-ios Releases
[!TIP] "Platform"列表示该属性在原三方库上支持的平台。
[!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
Name | Description | Type | Required | Platform | HarmonyOS Support |
---|---|---|---|---|---|
presentLocalNotification | Schedules the localNotification for immediate presentation. | function | no | iOS | yes |
scheduleLocalNotification | Schedules the localNotification for future presentation | function | no | iOS | yes |
cancelAllLocalNotifications | Cancels all scheduled localNotifications | function | no | iOS | yes |
addEventListener | Attaches a listener to remote or local notification events while the app is running in the foreground or the background. | function | no | iOS | no |
removeEventListener | Removes the event listener. Do this in componentWillUnmount to prevent memory leaks | function | no | iOS | no |
addNotificationRequest | Sends notificationRequest to notification center at specified firedate. Fires immediately if firedate is not set. | function | no | iOS | yes |
getDeliveredNotifications | Provides you with a list of the app’s notifications that are still displayed in Notification Center | function | no | iOS | yes |
removeAllDeliveredNotifications | Remove all delivered notifications from Notification Center | function | no | iOS | yes |
removeDeliveredNotifications | Removes the specified delivered notifications from Notification Center | function | no | iOS | yes |
setApplicationIconBadgeNumber | Sets the badge number for the app icon on the home screen | function | no | iOS | yes |
getApplicationIconBadgeNumber | Gets the current badge number for the app icon on the home screen | function | no | iOS | no |
cancelLocalNotifications | Cancel local notifications | function | no | iOS | no |
requestPermissions | Requests notification permissions from iOS, prompting the user's dialog box. By default, it will request all notification permissions, but a subset of these can be requested by passing a map of requested permissions. The following permissions are supported | function | no | iOS | yes |
abandonPermissions | Unregister for all remote notifications received via Apple Push Notification service | function | no | iOS | no |
checkPermissions | See what push permissions are currently enabled | function | no | iOS | yes |
getInitialNotification | This method returns a promise. If the app was launched by a push notification, this promise resolves to an object of type PushNotificationIOS. Otherwise, it resolves to null. | function | no | iOS | no |
getScheduledLocalNotifications | Gets the local notifications that are currently scheduled | function | no | iOS | no |
[!TIP] "Platform"列表示该属性在原三方库上支持的平台。
[!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
Name | Description | Type | Required | Platform | HarmonyOS Support |
---|---|---|---|---|---|
id | Identifier of the notification | string | no | All | yes |
title | A short description of the reason for the notification | string | yes | All | yes |
subtitle | A secondary description of the reason for the notification | string | no | All | no |
body | The message displayed in the notificatio | string | yes | All | yes |
badge | The number to display as the app's icon badge | number | no | All | yes |
fireDate | The date and time when the system should deliver the notification | object | no | All | yes |
repeats | Sets notification to repeat | boolean | no | All | no |
repeatsComponent | An object indicating which parts of fireDate should be repeated | object | no | All | no |
sound | The sound played when the notification is fired | string | no | All | no |
category | The category of this notification, required for actionable notifications | string | no | All | no |
isSilent | If true, the notification will appear without sound | boolean | no | All | yes |
isCritical | If true, the notification sound be played even when the device is locked, muted, or has Do Not Disturb enabled | boolean | no | All | no |
criticalSoundVolume | A number between 0 and 1 for volume of critical notification. Default volume will be used if not specified | number | no | All | no |
userInfo | An object containing additional notification data | object | no | All | yes |
isTimeZoneAgnostic | If true, fireDate adjusted automatically upon time zone changes (e.g. for an alarm clock) | boolean | no | All | no |
interruptionLevel | A string specifying the interruption level. Valid values are 'active' , 'passive' , 'timeSensitive' , or 'critical' | string | no | All | no |
本项目基于 The MIT License (MIT) ,请自由地享受和参与开源。
FAQs
React Native Push Notification API for iOS
We found that @ohmi/push-notification-ios demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.