Skip to content

Commit e1344d4

Browse files
authored
Merge pull request #542 from OneSignal/add_setLaunchURLsInApp
Add iOS only `setLaunchURLsInApp` function
2 parents 6ddc347 + 841c204 commit e1344d4

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

example/lib/main.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class _MyAppState extends State<MyApp> {
103103
await OneSignal.shared
104104
.setAppId("380dc082-5231-4cc2-ab51-a03da5a0e4c2");
105105

106+
// iOS-only method to open launch URLs in Safari when set to false
107+
OneSignal.shared.setLaunchURLsInApp(false);
108+
106109
bool requiresConsent = await OneSignal.shared.requiresUserPrivacyConsent();
107110

108111
this.setState(() {

ios/Classes/OneSignalPlugin.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
125125
[self disablePush:call withResult:result];
126126
else if ([@"OneSignal#postNotification" isEqualToString:call.method])
127127
[self postNotification:call withResult:result];
128+
else if ([@"OneSignal#setLaunchURLsInApp" isEqualToString:call.method])
129+
[self setLaunchURLsInApp:call withResult:result];
128130
else if ([@"OneSignal#promptLocation" isEqualToString:call.method])
129131
[self promptLocation:call withResult:result];
130132
else if ([@"OneSignal#setLocationShared" isEqualToString:call.method])
@@ -244,6 +246,12 @@ - (void)postNotification:(FlutterMethodCall *)call withResult:(FlutterResult)res
244246
}];
245247
}
246248

249+
- (void)setLaunchURLsInApp:(FlutterMethodCall *)call withResult:(FlutterResult)result {
250+
BOOL isEnabled = [call.arguments[@"isEnabled"] boolValue];
251+
[OneSignal setLaunchURLsInApp:isEnabled];
252+
result(nil);
253+
}
254+
247255
- (void)promptLocation:(FlutterMethodCall *)call withResult:(FlutterResult)result {
248256
[OneSignal promptLocation];
249257
result(nil);

lib/onesignal_flutter.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'dart:io' show Platform;
23
import 'package:flutter/services.dart';
34
import 'package:onesignal_flutter/src/permission.dart';
45
import 'package:onesignal_flutter/src/subscription.dart';
@@ -164,6 +165,19 @@ class OneSignal {
164165
{'notificationId': notificationId, 'shouldDisplay': shouldDisplay});
165166
}
166167

168+
/// Only applies to iOS
169+
/// Sets if launch URLs should be opened within the application or in Safari.
170+
/// When set to true, launch URLs will open an in-app browser.
171+
Future<void> setLaunchURLsInApp(bool isEnabled) async {
172+
if (Platform.isIOS) {
173+
await _channel.invokeMethod(
174+
"OneSignal#setLaunchURLsInApp", {'isEnabled': isEnabled});
175+
} else {
176+
_onesignalLog(OSLogLevel.info,
177+
"setLaunchURLsInApp: this function is not supported on Android");
178+
}
179+
}
180+
167181
/// Allows you to completely disable the SDK until your app calls the
168182
/// OneSignal.consentGranted(true) function. This is useful if you want
169183
/// to show a Terms and Conditions or privacy popup for GDPR.

0 commit comments

Comments
 (0)