Skip to content

Commit 3891a70

Browse files
committed
Adding bridging for live activities
1 parent 8ae9f60 commit 3891a70

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

ios/Classes/OneSignalPlugin.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
153153
[self initNotificationWillShowInForegroundHandlerParams];
154154
else if ([@"OneSignal#completeNotification" isEqualToString:call.method])
155155
[self completeNotification:call withResult:result];
156+
else if ([@"OneSignal#enterLiveActivity" isEqualToString:call.method])
157+
[self enterLiveActivity:call withResult:result];
158+
else if ([@"OneSignal#exitLiveActivity" isEqualToString:call.method])
159+
[self exitLiveActivity:call withResult:result];
156160
else
157161
result(FlutterMethodNotImplemented);
158162
}
@@ -403,6 +407,30 @@ - (void)completeNotification:(FlutterMethodCall *)call withResult:(FlutterResult
403407
[self.receivedNotificationCache removeObjectForKey:notificationId];
404408
}
405409

410+
#pragma mark Live Activity
411+
412+
- (void)enterLiveActivity:(FlutterMethodCall *)call withResult:(FlutterResult)result {
413+
NSString *activityId = call.arguments[@"activityId"];
414+
NSString *token = call.arguments[@"token"];
415+
416+
[OneSignal enterLiveActivity:activityId withToken:token withSuccess:^(NSDictionary *results) {
417+
result(results);
418+
} withFailure:^(NSError *error) {
419+
[OneSignal onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"enterLiveActivity Failure with error: %@", error]];
420+
result(error.flutterError);
421+
}];
422+
}
423+
424+
- (void)exitLiveActivity:(FlutterMethodCall *)call withResult:(FlutterResult)result {
425+
NSString *activityId = call.arguments[@"activityId"];
426+
427+
[OneSignal exitLiveActivity:activityId withSuccess:^(NSDictionary *results) {
428+
result(results);
429+
} withFailure:^(NSError *error) {
430+
[OneSignal onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"exitLiveActivity Failure with error: %@", error]];
431+
result(error.flutterError);
432+
}];
433+
}
406434

407435
#pragma mark In App Message Click Handler
408436
- (void)handleInAppMessageClicked:(OSInAppMessageAction *)action {

lib/onesignal_flutter.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,29 @@ class OneSignal {
312312
return await _channel.invokeMethod("OneSignal#clearOneSignalNotifications");
313313
}
314314

315+
/// Only applies to iOS
316+
/// Associates a temporary push token with an Activity ID on the OneSignal server.
317+
Future<void> enterLiveActivity(String activityId, String token) async {
318+
if (Platform.isIOS) {
319+
await _channel.invokeMethod("OneSignal#enterLiveActivity", {'activityId': activityId, 'token': token});
320+
} else {
321+
_onesignalLog(OSLogLevel.info,
322+
"enterLiveActivity: this function is not supported on Android");
323+
}
324+
}
325+
326+
/// Only applies to iOS
327+
/// Deletes activityId associated temporary push token on the OneSignal server.
328+
Future<void> exitLiveActivity(String activityId) async {
329+
if (Platform.isIOS) {
330+
await _channel.invokeMethod("OneSignal#exitLiveActivity",
331+
{'activityId': activityId});
332+
} else {
333+
_onesignalLog(OSLogLevel.info,
334+
"exitLiveActivity: this function is not supported on Android");
335+
}
336+
}
337+
315338
/// Allows you to manually cancel a single OneSignal notification based on its Android notification integer ID
316339
void removeNotification(int notificationId) {
317340
_channel.invokeMethod("OneSignal#removeNotification",

0 commit comments

Comments
 (0)