Skip to content

Commit b536ae0

Browse files
authored
Merge pull request #621 from OneSignal/feat/ios_live_activity_support
Add Live Activities support
2 parents 9222eca + 3891a70 commit b536ae0

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

example/lib/main.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,14 @@ class OneSignalButtonState extends State<OneSignalButton> {
580580
return new Table(
581581
children: [
582582
new TableRow(children: [
583-
new FlatButton(
584-
disabledColor: Color.fromARGB(180, 212, 86, 83),
585-
disabledTextColor: Colors.white,
586-
color: Color.fromARGB(255, 212, 86, 83),
587-
textColor: Colors.white,
588-
padding: EdgeInsets.all(8.0),
583+
new TextButton(
584+
style: TextButton.styleFrom(
585+
foregroundColor:Colors.white,
586+
disabledForegroundColor: Colors.white,
587+
backgroundColor: Color.fromARGB(255, 212, 86, 83),
588+
disabledBackgroundColor:Color.fromARGB(180, 212, 86, 83),
589+
padding: EdgeInsets.all(8.0),
590+
),
589591
child: new Text(widget.title),
590592
onPressed: widget.enabled ? widget.onPressed : null,
591593
)

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 {

ios/onesignal_flutter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
1313
s.source_files = 'Classes/**/*'
1414
s.public_header_files = 'Classes/**/*.h'
1515
s.dependency 'Flutter'
16-
s.dependency 'OneSignalXCFramework', '3.11.4'
16+
s.dependency 'OneSignalXCFramework', '3.12.3'
1717
s.ios.deployment_target = '9.0'
1818
s.static_framework = true
1919
end

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)