Skip to content

Commit

Permalink
feat(signOut) Implementing signOut on iOS (#37)
Browse files Browse the repository at this point in the history
* Removing checkRecentNotification on setNotificationOpenedHandler

Stop getting the last push payload every time handler is set

* Adding signOut function to iOS

* Code formatting

* reverting checkRecentNotification

* Updating readMe
  • Loading branch information
Gabriel-Azevedo authored Jan 17, 2022
1 parent 8d87cd7 commit 0601a97
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To use this plugin, add `iterable_flutter` as a [dependency in your pubspec.yaml
| `setUserId` | X | X | |
| `registerForPush` | X | X | |
| `updateUser` | X | X | |
| `signOut` | X | | |
| `signOut` | X | X | |
| `track` | X | X | |
| `setNotificationOpenedHandler` | X | X | |

Expand Down
11 changes: 11 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class _MyAppState extends State<MyApp> {
await IterableFlutter.track(event);
}

Future<void> signOut() async {
await IterableFlutter.signOut();
}

/// Call it to register device for current user if calling setEmail or
/// setUserId after the app has already launched
/// (for example, when a new user logs in)
Expand Down Expand Up @@ -131,6 +135,13 @@ class _MyAppState extends State<MyApp> {
),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
signOut();
},
child: Text('Sign Out'),
),
SizedBox(height: 20),
Text("Push: $pushData"),
Text("Body: ${pushData['body']}"),
Text("Title: ${pushData['title']}"),
Expand Down
8 changes: 8 additions & 0 deletions ios/Classes/SwiftIterableFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public class SwiftIterableFlutterPlugin: NSObject, FlutterPlugin, UNUserNotifica
case "registerForPush":
registerForPushNotifications()

result(nil)
case "signOut":
signOut()

result(nil)
default:
result(FlutterMethodNotImplemented)
Expand All @@ -74,6 +78,10 @@ public class SwiftIterableFlutterPlugin: NSObject, FlutterPlugin, UNUserNotifica
}
return [:];
}

func signOut() {
IterableAPI.disableDeviceForCurrentUser()
}

public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [AnyHashable : Any] = [:]) -> Bool {
UNUserNotificationCenter.current().delegate = self
Expand Down

0 comments on commit 0601a97

Please sign in to comment.