Skip to content

Commit

Permalink
Add iOS version checks consistently
Browse files Browse the repository at this point in the history
Remove autorelease pool
  • Loading branch information
brismithers committed May 14, 2024
1 parent 452f6bd commit bd03ab7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ios/Classes/OSFlutterLiveActivities.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,34 @@ - (void)exitLiveActivity:(FlutterMethodCall *)call withResult:(FlutterResult)res
- (void)setPushToStartToken:(FlutterMethodCall *)call withResult:(FlutterResult)result {
NSString *activityType = call.arguments[@"activityType"];
NSString *token = call.arguments[@"token"];
NSError* err=nil;

@autoreleasepool {
NSError* err=nil;
if (@available(iOS 17.2, *)) {
[OneSignalLiveActivitiesManagerImpl setPushToStartToken:activityType withToken:token error:&err];
if (err) {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"activityType must be the name of your ActivityAttributes struct"]];
}
} else {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"cannot setPushToStartToken on iOS < 17.2"]];
}

result(nil);
}

- (void)removePushToStartToken:(FlutterMethodCall *)call withResult:(FlutterResult)result {
NSString *activityType = call.arguments[@"activityType"];
NSError* err=nil;

@autoreleasepool {
NSError* err=nil;
if (@available(iOS 17.2, *)) {
[OneSignalLiveActivitiesManagerImpl removePushToStartToken:activityType error:&err];
if (err) {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"activityType must be the name of your ActivityAttributes struct"]];
}
} else {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"cannot removePushToStartToken on iOS < 17.2"]];
}

result(nil);
}

- (void)setupDefault:(FlutterMethodCall *)call withResult:(FlutterResult)result {
Expand All @@ -120,6 +128,8 @@ - (void)setupDefault:(FlutterMethodCall *)call withResult:(FlutterResult)result
} else {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"cannot setupDefault on iOS < 16.1"]];
}

result(nil);
}

- (void)startDefault:(FlutterMethodCall *)call withResult:(FlutterResult)result {
Expand All @@ -132,6 +142,8 @@ - (void)startDefault:(FlutterMethodCall *)call withResult:(FlutterResult)result
} else {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"cannot startDefault on iOS < 16.1"]];
}

result(nil);
}

@end

0 comments on commit bd03ab7

Please sign in to comment.