Skip to content

Commit

Permalink
Merge pull request #542 from OneSignal/add_setLaunchURLsInApp
Browse files Browse the repository at this point in the history
Add iOS only `setLaunchURLsInApp` function
  • Loading branch information
nan-li authored Mar 10, 2022
2 parents 6ddc347 + 841c204 commit e1344d4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class _MyAppState extends State<MyApp> {
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(() {
Expand Down
8 changes: 8 additions & 0 deletions ios/Classes/OneSignalPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions lib/onesignal_flutter.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<void> 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.
Expand Down

0 comments on commit e1344d4

Please sign in to comment.