【发布时间】:2019-06-30 20:42:40
【问题描述】:
我有一个使用 Unity 创建的 android 应用程序,我可以从 OneSignal 网站和我的 php 网站成功地向这个应用程序发送通知。现在我想从颤振应用程序(android)发送通知。我尝试了用于颤振示例的 onesignal sdk,但它将通知发送到颤振应用程序而不是 Unity 应用程序。我不知道我哪里错了:
Future<void> initPlatformState() async {
if (!mounted) return;
var settings = {
OSiOSSettings.autoPrompt: false,
OSiOSSettings.promptBeforeOpeningPushUrl: true
};
// NOTE: Replace with your own app ID from https://www.onesignal.com
await OneSignal.shared
.init("9a98990f-40fa-455e-adda-ccd474594f41", iOSSettings: settings);
OneSignal.shared
.setInFocusDisplayType(OSNotificationDisplayType.notification);
bool requiresConsent = await OneSignal.shared.requiresUserPrivacyConsent();
this.setState(() {
_enableConsentButton = requiresConsent;
});
}
void _handleSendNotification() async {
var status = await OneSignal.shared.getPermissionSubscriptionState();
var playerId = status.subscriptionStatus.userId;
var imgUrlString =
"https://vaars.000webhostapp.com/MrNutella/logonutella.png";
var notification = OSCreateNotification(
playerIds: [playerId],
content: "this is a test from OneSignal's Flutter SDK",
heading: "Test Notification",
iosAttachments: {"id1": imgUrlString},
bigPicture: imgUrlString,
buttons: [
OSActionButton(text: "test1", id: "id1"),
OSActionButton(text: "test2", id: "id2")
]);
var response = await OneSignal.shared.postNotification(notification);
this.setState(() {
_debugLabelString = "Sent notification with response: $response";
});
}
【问题讨论】:
标签: flutter push-notification onesignal