Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
}

dependencies {
compile('com.onesignal:OneSignal:3.10.3')
compile('com.onesignal:OneSignal:3.10.5')
}

// Adds required manifestPlaceholders keys to allow mainifest merge gradle step to complete
Expand Down
16 changes: 16 additions & 0 deletions android/src/main/java/com/onesignal/flutter/OneSignalPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ else if (call.method.contentEquals("OneSignal#promptPermission"))
Log.e("onesignal", "promptPermission() is not applicable in Android.");
else if (call.method.contentEquals("OneSignal#didSetNotificationOpenedHandler"))
this.didSetNotificationOpenedHandler();
else if (call.method.contentEquals("OneSignal#setExternalUserId"))
this.setExternalUserId(call, result);
else if (call.method.contentEquals("OneSignal#removeExternalUserId"))
this.removeExternalUserId(result);
else
result.notImplemented();
}
Expand Down Expand Up @@ -250,6 +254,18 @@ private void didSetNotificationOpenedHandler() {
}
}

private void setExternalUserId(MethodCall call, Result result) {
OneSignal.setExternalUserId((String)call.argument("externalUserId"));

result.success(null);
}

private void removeExternalUserId(Result result) {
OneSignal.removeExternalUserId();

result.success(null);
}

@Override
public void onOSSubscriptionChanged(OSSubscriptionStateChanges stateChanges) {
this.channel.invokeMethod("OneSignal#subscriptionChanged", OneSignalSerializer.convertSubscriptionStateChangesToMap(stateChanges));
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ target 'Runner' do
end

target 'OneSignalNotificationServiceExtension' do
pod 'OneSignal', '>= 2.9.3', '< 3.0'
pod 'OneSignal', '>= 2.9.4', '< 3.0'
end

post_install do |installer|
Expand Down
46 changes: 45 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
String _debugLabelString = "";
String _emailAddress;
String _externalUserId;
bool _enableConsentButton = false;

// CHANGE THIS parameter to true if you want to test GDPR privacy consent
Expand Down Expand Up @@ -165,6 +166,21 @@ class _MyAppState extends State<MyApp> {
});
}

void _handleSetExternalUserId() {
print("Setting external user ID");
OneSignal.shared.setExternalUserId(_externalUserId);
this.setState(() {
_debugLabelString = "Set External User ID";
});
}

void _handleRemoveExternalUserId() {
OneSignal.shared.removeExternalUserId();
this.setState(() {
_debugLabelString = "Removed external user ID";
});
}

void _handleSendNotification() async {
var status = await OneSignal.shared.getPermissionSubscriptionState();

Expand Down Expand Up @@ -285,12 +301,40 @@ class _MyAppState extends State<MyApp> {
new OneSignalButton("Post Silent Notification",
_handleSendSilentNotification, !_enableConsentButton)
]),
new TableRow(children: [
new TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
hintText: "External User ID",
labelStyle: TextStyle(
color: Color.fromARGB(255, 212, 86, 83),
)),
onChanged: (text) {
this.setState(() {
_externalUserId = text == "" ? null : text;
});
},
)
]),
new TableRow(children: [
Container(
height: 8.0,
)
]),
new TableRow(children: [
new OneSignalButton(
"Set External User ID", _handleSetExternalUserId, !_enableConsentButton)
]),
new TableRow(children: [
new OneSignalButton(
"Remove External User ID", _handleRemoveExternalUserId, !_enableConsentButton)
]),
new TableRow(children: [
new Container(
child: new Text(_debugLabelString),
alignment: Alignment.center,
)
])
]),
],
),
),
Expand Down
3 changes: 0 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ description: Demonstrates how to use the onesignal plugin.
dependencies:
flutter:
sdk: flutter

flutter_test:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
Expand Down
4 changes: 4 additions & 0 deletions ios/Classes/OneSignalPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
[self logoutEmail:call withResult:result];
} else if ([@"OneSignal#didSetNotificationOpenedHandler" isEqualToString:call.method]) {
[self didSetNotificationOpenedHandler];
} else if ([@"OneSignal#setExternalUserId" isEqualToString:call.method]) {
[OneSignal setExternalUserId:call.arguments[@"externalUserId"]];
} else if ([@"OneSignal#removeExternalUserId" isEqualToString:call.method]) {
[OneSignal removeExternalUserId];
} else {
result(FlutterMethodNotImplemented);
}
Expand Down
2 changes: 1 addition & 1 deletion ios/onesignal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Pod::Spec.new do |s|
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'OneSignal', '>= 2.9.3', '< 3.0'
s.dependency 'OneSignal', '>= 2.9.4', '< 3.0'
s.ios.deployment_target = '8.0'
end

12 changes: 12 additions & 0 deletions lib/onesignal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ class OneSignal {
return await _channel.invokeMethod("OneSignal#logoutEmail");
}

/// OneSignal allows you to set a custom ID for your users. This makes it so that
/// if your app has its own user ID's, you can use your own custom user ID's with
/// our API instead of having to save their OneSignal user ID's.
Future<void> setExternalUserId(String externalId) async {
return await _channel.invokeMethod("OneSignal#setExternalUserId", {'externalUserId' : externalId});
}

/// Removes the external user ID that was set for the current user.
Future<void> removeExternalUserId() async {
return await _channel.invokeMethod("OneSignal#removeExternalUserId");
}

// Private function that gets called by ObjC/Java
Future<Null> _handleMethod(MethodCall call) async {
if (call.method == 'OneSignal#handleReceivedNotification' &&
Expand Down
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ dependencies:
sdk: flutter

dev_dependencies:
test: ^1.5.1
flutter_test:
sdk: flutter

environment:
sdk: ">=2.1.0-dev.7.1 <3.0.0"
flutter: ">=0.10.1-pre.45 <2.0.0"
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=0.1.4 <2.0.0"
7 changes: 7 additions & 0 deletions test/mock_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class OneSignalMockChannelController {
case "OneSignal#deleteTags":
this.state.deleteTags = call.arguments;
return {"success": true};
case "OneSignal#setExternalUserId":
this.state.externalId = (call.arguments as Map<dynamic, dynamic>)['externalUserId'] as String;
return {"success" : true};
case "OneSignal#removeExternalUserId":
this.state.externalId = null;
return {"success" : true};
}
}
}
Expand All @@ -90,6 +96,7 @@ class OneSignalState {
bool locationShared;
OSNotificationDisplayType inFocusDisplayType;
bool subscriptionState;
String externalId;

// tags
Map<dynamic, dynamic> tags;
Expand Down
12 changes: 12 additions & 0 deletions test/onesignal_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,16 @@ void main() {
expect(channelController.state.deleteTags, ['test1']);
}));
});

test('setting external user ID', () {
onesignal.setExternalUserId('test_ext_id').then(expectAsync1((v) {
expect(channelController.state.externalId, 'test_ext_id');
}));
});

test('removing external user ID', () {
onesignal.removeExternalUserId().then(expectAsync1((v) {
expect(channelController.state.externalId, null);
}));
});
}