有什么方法可以打开来自webview上onesignal的链接吗?

时间:2019-06-19 14:13:22

标签: flutter dart onesignal

我在Flutter应用中使用了Webview小部件,我想在用户点击通知时打开一个链接,该链接来自一个信号上的其他数据 我试图做这个但没用
我的代码:

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:onesignal/onesignal.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
String _debugLabelString = "";
String url = "https://www.google.com";


@override
void initState() {
super.initState();
initPlatformState();
}

Future<void> initPlatformState() async {
if (!mounted) return;

OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);

OneSignal.shared.setRequiresUserPrivacyConsent(_requireConsent);

var settings = {
  OSiOSSettings.autoPrompt: false,
  OSiOSSettings.promptBeforeOpeningPushUrl: true
};

OneSignal.shared.setNotificationReceivedHandler((notification) {
  this.setState(() {
    url = notification.payload.additionalData['url'].toString() ;

  });
});

OneSignal.shared
    .setNotificationOpenedHandler((OSNotificationOpenedResult result) {
  this.setState(() {
  // the value of result.notification.payload.additionalData['url'] = 
  // https://www.facebook.com/
    url = result.notification.payload.additionalData['url'].toString() ;
  });
});


// NOTE: Replace with your own app ID from https://www.onesignal.com
await OneSignal.shared
    .init("086d22bd-5539-4849-9db2-01589fd3429d", iOSSettings: settings);

OneSignal.shared
    .setInFocusDisplayType(OSNotificationDisplayType.notification);


}



@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('OneSignal Flutter Demo'),
backgroundColor: Color.fromARGB(255, 212, 86, 83),
),
body:  WebviewScaffold(
        url: url,

        withJavascript: true,
      )
  ),
);
}
}

我在其他数据中添加了facebook.com,它显示了google页面,而不是在facebook中如何显示我添加了其他数据的保存值

1 个答案:

答案 0 :(得分:0)

setNotificationReceivedHandler为在前台 上收到通知的事件创建回调。

对于“通知打开时”回调(如果它在后台运行,则适用),请使用setNotificationOpened处理程序。

Flutter event handler reference

如果您希望在后台处理此问题,而无论是否打开通知,请参阅Background Notifications(注意:准备在此处编写本机代码)