我在我的应用程序中使用One Signal Push通知.当我的应用程序处于关闭状态时,意味着当我不使用我的应用程序时,我会从我的测试团队发出的一个信号中获得推送通知.但是当我使用应用程序时,我没有得到它.
你的回答更受赞赏.
我正在尝试将OneSignal SDK添加到我的 Android 库项目中。因此,我在我的库中添加了必要的依赖项,build.gradle并且还manifestPlaceholders:
// One Signal:
manifestPlaceholders = [onesignal_app_id: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: "XXXXXXXXXXXX"]
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试构建一个使用我添加了 OneSignal 的库的演示应用程序时,我收到以下错误:
/path_to_project/demoapp/demoapp/src/main/AndroidManifest.xml Error:
Attribute meta-data#onesignal_app_id@value at AndroidManifest.xml requires a placeholder substitution but no value for <onesignal_app_id> is provided.
/path_to_project/demoapp/demoapp/src/main/AndroidManifest.xml Error:
Attribute meta-data#onesignal_google_project_number@value at AndroidManifest.xml requires a placeholder substitution but no value for <onesignal_google_project_number> is provided.
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
:demoapp:processDebugManifest FAILED
FAILURE: Build failed …Run Code Online (Sandbox Code Playgroud) android android-manifest android-library android-gradle-plugin onesignal
在我的应用程序中,我通过一个信号向用户发送通知。但有时一个信号返回 null 用户 ID...那时我面临向用户发送通知的问题。我该如何解决它。如果有人有解决方案,请与我分享
这是我生成用户 ID 的代码
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
@Override
public void idsAvailable(String userId, String registrationId) {
Log.d("test","key is"+notification_key);
notification_key=userId;
}
});
Run Code Online (Sandbox Code Playgroud)
我正在 MyApplication.class 中初始化一个信号
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 React Native 应用程序中配置OneSignal React Native以用于推送通知。
环境设置
我按照React Native One Signal 官方文档中的以下步骤进行设置:
步骤 1 : npm install -g react-native-cli, 状态 : 完成
步骤 2 : react-native init OneSignalDemo, 状态 : 完成
在链接项目之前,我使用以下命令成功运行了我的项目:
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
react-native run-android
Run Code Online (Sandbox Code Playgroud)
第 3 步:在链接我的库时,react-native link react-native-onesignal我的终端出现错误。将 oneSignal 与我的应用程序链接(根据官方文档),状态:失败
错误:
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
react-native run-android …Run Code Online (Sandbox Code Playgroud) 我试图让我的扑动应用程序在后台处理通知。我正在使用带有 onesignal 的推送通知,当我滑动我的应用程序并关闭它时,它不再调用 onReceiveHandler 。所以我读到了NotificationExtenderService: https://documentation.onesignal.com/docs/service-extensions#section-notification-extender-service
所以首先我在 android>app>main>java>..>NotificationsService.java 中创建了一个类,位于 MainActivity.java 旁边
并将其添加到 AndroidMainfest.xml 中,该文件位于 android>app>main 文件夹中:
<service
android:name=".YOUR_CLASS_NAME"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false">
<intent-filter>
<action android:name="com.onesignal.NotificationExtender" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
因此,在没有做任何其他工作的情况下,我尝试运行我的应用程序,只是为了看看它在完成 flutter clean 等操作后是否没有显示任何错误。
但它似乎无法识别类方法和内容:
import com.onesignal.OSNotificationPayload;
import com.onesignal.NotificationExtenderService;
public class NotificationExtenderBareBonesExample extends NotificationExtenderService {
@Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
// Read properties from result.
// Return true to stop the notification from displaying.
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
显示以下错误:
error: cannot find symbol
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
^
symbol: class OSNotificationReceivedResult
location: …Run Code Online (Sandbox Code Playgroud) 使用 React Native 和 OneSignal 时如何在 Android 上全屏显示时间敏感的通知?
这些通知是在接到电话或闹钟响起时发出的,并且应用程序显示居中的全屏通知而不是托盘通知。是否可以使用 React Native 来实现这样的通知?
Android 文档中的参考资料:
push-notification android-notifications react-native onesignal
在检查控制台后,我尝试使用简单的方法在网站上实现一个信号通知,它向我显示此错误。如何在我的网站中实现单一信号通知?
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
<script>
window.OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.init({
appId: "c208302-0-284011-12E8D",
});
});
</script>
ServiceWorkerManager.js:399 [Service Worker Installation] Installing service worker failed TypeError: Failed to register a ServiceWorker for scope ('https://www.simplenikah.pk/') with script ('https://www.simplenikah.pk/OneSignalSDKWorker.js?appId=c3aca046-2d30-4703-9454-c9f2666e3ac1'): A bad HTTP response code (404) was received when fetching the script.
(anonymous) @ ServiceWorkerManager.js:399
a @ tslib.es6.js:63
/OneSignalSDKWorker.js?appId=c3aca046-2d30-4703-9454-c9f2666e3ac1:1 Failed to load resource: the server responded with a status of 404 ()
OneSignalError.js:18 Uncaught (in promise) Pe: Registration of a Service Worker …Run Code Online (Sandbox Code Playgroud) 我有一个 Next.js 应用程序,我使用next-pwa离线模式。现在我想添加推送通知(OneSignal解决方案),我看过很多文章/教程,它们都需要创建/更新服务工作者。
所以我的问题是:我该如何做到这一点,因为服务工作人员是由 生成的next-pwa,并且由于它已缩小而似乎不可编辑。
当我想将 onesignal 添加到 flutter 时,出现以下错误。我该如何解决?
我按照本指南在我的反应本机应用程序中设置 OneSignal 后台通知:https ://documentation.onesignal.com/docs/rn-android-native-module-setup-for-notification-service-extension#ios-notification-服务扩展模块
当我通过 Xcode 将应用程序直接安装到我的设备时,后台通知按预期工作。但是当我存档构建并从 TestFlight 安装它时,后台通知不起作用。除非emitNotificationEvent我添加的事件没有被触发,即使收到了推送通知。
当我在 Xcode 中跟踪存档构建的问题(使用设备控制台)时,_instance注意到NotificationExtensionModule.m. 有人遇到过类似的问题或知道可能是什么原因吗?
笔记
添加代码片段以进一步了解我的问题:
AppDelegate.h
#import <Foundation/Foundation.h>
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,RCTBridgeDelegate,UNUserNotificationCenterDelegate>
@property (nonatomic, strong) UIWindow *window;
@end
Run Code Online (Sandbox Code Playgroud)
AppDelegate.m
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
//access NotificationServiceExtensionModule emitNotificationEvent method
[NotificationServiceExtensionModule.sharedInstance emitNotificationEvent:userInfo ];
completionHandler(UIBackgroundFetchResultNoData);
}
Run Code Online (Sandbox Code Playgroud)
通知服务扩展模块.h
#import <foundation/Foundation.h>
// NotificationServiceExtensionModule.h
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
@interface NotificationServiceExtensionModule : …Run Code Online (Sandbox Code Playgroud) ios testflight react-native onesignal react-native-onesignal
onesignal ×10
react-native ×3
android ×2
flutter ×2
javascript ×2
ios ×1
next-pwa ×1
next.js ×1
reactjs ×1
testflight ×1