From 841c2047ea57bc9aa1f748fb41cf93ff0176af5f Mon Sep 17 00:00:00 2001 From: Nan Date: Thu, 10 Mar 2022 09:51:29 -0800 Subject: [PATCH] Add missing iOS `setLaunchURLsInApp` function --- example/lib/main.dart | 3 +++ ios/Classes/OneSignalPlugin.m | 8 ++++++++ lib/onesignal_flutter.dart | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/example/lib/main.dart b/example/lib/main.dart index 49f801a3..d48e07eb 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -103,6 +103,9 @@ class _MyAppState extends State { await OneSignal.shared .setAppId("380dc082-5231-4cc2-ab51-a03da5a0e4c2"); + // iOS-only method to open launch URLs in Safari when set to false + OneSignal.shared.setLaunchURLsInApp(false); + bool requiresConsent = await OneSignal.shared.requiresUserPrivacyConsent(); this.setState(() { diff --git a/ios/Classes/OneSignalPlugin.m b/ios/Classes/OneSignalPlugin.m index a7c1efb0..62ad17b3 100644 --- a/ios/Classes/OneSignalPlugin.m +++ b/ios/Classes/OneSignalPlugin.m @@ -125,6 +125,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { [self disablePush:call withResult:result]; else if ([@"OneSignal#postNotification" isEqualToString:call.method]) [self postNotification:call withResult:result]; + else if ([@"OneSignal#setLaunchURLsInApp" isEqualToString:call.method]) + [self setLaunchURLsInApp:call withResult:result]; else if ([@"OneSignal#promptLocation" isEqualToString:call.method]) [self promptLocation:call withResult:result]; else if ([@"OneSignal#setLocationShared" isEqualToString:call.method]) @@ -244,6 +246,12 @@ - (void)postNotification:(FlutterMethodCall *)call withResult:(FlutterResult)res }]; } +- (void)setLaunchURLsInApp:(FlutterMethodCall *)call withResult:(FlutterResult)result { + BOOL isEnabled = [call.arguments[@"isEnabled"] boolValue]; + [OneSignal setLaunchURLsInApp:isEnabled]; + result(nil); +} + - (void)promptLocation:(FlutterMethodCall *)call withResult:(FlutterResult)result { [OneSignal promptLocation]; result(nil); diff --git a/lib/onesignal_flutter.dart b/lib/onesignal_flutter.dart index a1dadeb4..94a96e71 100644 --- a/lib/onesignal_flutter.dart +++ b/lib/onesignal_flutter.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:io' show Platform; import 'package:flutter/services.dart'; import 'package:onesignal_flutter/src/permission.dart'; import 'package:onesignal_flutter/src/subscription.dart'; @@ -164,6 +165,19 @@ class OneSignal { {'notificationId': notificationId, 'shouldDisplay': shouldDisplay}); } + /// Only applies to iOS + /// Sets if launch URLs should be opened within the application or in Safari. + /// When set to true, launch URLs will open an in-app browser. + Future setLaunchURLsInApp(bool isEnabled) async { + if (Platform.isIOS) { + await _channel.invokeMethod( + "OneSignal#setLaunchURLsInApp", {'isEnabled': isEnabled}); + } else { + _onesignalLog(OSLogLevel.info, + "setLaunchURLsInApp: this function is not supported on Android"); + } + } + /// Allows you to completely disable the SDK until your app calls the /// OneSignal.consentGranted(true) function. This is useful if you want /// to show a Terms and Conditions or privacy popup for GDPR.