Skip to content

Cherry-picked support for iOS 12.5 from upstream #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 12 additions & 4 deletions ios/CovidShield.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
843B6BB825722A8400D445C5 /* URWGeometric-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 843B6BB625722A8400D445C5 /* URWGeometric-Bold.ttf */; };
9DCF98527548A48AED34959C /* libPods-CovidShield-CovidShieldTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 77A1C8C77A874BCC9042935F /* libPods-CovidShield-CovidShieldTests.a */; };
A10A691626414D8AABBB659C /* Device-Large.png in Resources */ = {isa = PBXBuildFile; fileRef = 431D5AB0AA364B5C9E7BFF1D /* Device-Large.png */; };
A40D59F9258A44E6009DA167 /* ExposureNotification.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A40D59F8258A44E6009DA167 /* ExposureNotification.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
A4E2F5EF258A84B50037F403 /* ENActivityHandling.m in Sources */ = {isa = PBXBuildFile; fileRef = A4E2F5EE258A84B50037F403 /* ENActivityHandling.m */; };
BA054BD27C1A8657F6BF95BB /* libPods-CovidShield.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 52445CBEB4F2B88669022976 /* libPods-CovidShield.a */; };
E0C908AD8D97409895BCF901 /* img_0.png in Resources */ = {isa = PBXBuildFile; fileRef = 94B4DC3E27534960AEAA5640 /* img_0.png */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -62,8 +64,9 @@
843B6BB525722A8400D445C5 /* URWGeometric-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "URWGeometric-Regular.ttf"; sourceTree = "<group>"; };
843B6BB625722A8400D445C5 /* URWGeometric-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "URWGeometric-Bold.ttf"; sourceTree = "<group>"; };
94B4DC3E27534960AEAA5640 /* img_0.png */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = img_0.png; path = ../src/assets/animation/images/img_0.png; sourceTree = "<group>"; };
B850EA562569729500300878 /* mn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = mn; path = "mn.lproj/Launch Screen.strings"; sourceTree = "<group>"; };
B850EA572569729500300878 /* mn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = mn; path = mn.lproj/InfoPlist.strings; sourceTree = "<group>"; };
A40D59F8258A44E6009DA167 /* ExposureNotification.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ExposureNotification.framework; path = System/Library/Frameworks/ExposureNotification.framework; sourceTree = SDKROOT; };
A4E2F5ED258A84B50037F403 /* ENActivityHandling.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ENActivityHandling.h; path = CovidShield/ENActivityHandling.h; sourceTree = "<group>"; };
A4E2F5EE258A84B50037F403 /* ENActivityHandling.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = ENActivityHandling.m; path = CovidShield/ENActivityHandling.m; sourceTree = "<group>"; };
DB9A1444C934C41C93EB531F /* Pods-CovidShield.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CovidShield.debug.xcconfig"; path = "Target Support Files/Pods-CovidShield/Pods-CovidShield.debug.xcconfig"; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
FA11CCD8EB9EB39453E3C0AA /* Pods-CovidShield-CovidShieldTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CovidShield-CovidShieldTests.debug.xcconfig"; path = "Target Support Files/Pods-CovidShield-CovidShieldTests/Pods-CovidShield-CovidShieldTests.debug.xcconfig"; sourceTree = "<group>"; };
Expand All @@ -84,6 +87,7 @@
buildActionMask = 2147483647;
files = (
BA054BD27C1A8657F6BF95BB /* libPods-CovidShield.a in Frameworks */,
A40D59F9258A44E6009DA167 /* ExposureNotification.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -139,6 +143,7 @@
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
isa = PBXGroup;
children = (
A40D59F8258A44E6009DA167 /* ExposureNotification.framework */,
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
52445CBEB4F2B88669022976 /* libPods-CovidShield.a */,
77A1C8C77A874BCC9042935F /* libPods-CovidShield-CovidShieldTests.a */,
Expand All @@ -164,6 +169,8 @@
74B6941D245F15B20077B9DA /* ExposureNotification.m */,
7482404D246F9C0E009F68EA /* CovidShield.h */,
7482404E246F9C0E009F68EA /* CovidShield.m */,
A4E2F5ED258A84B50037F403 /* ENActivityHandling.h */,
A4E2F5EE258A84B50037F403 /* ENActivityHandling.m */,
);
name = Libraries;
sourceTree = "<group>";
Expand Down Expand Up @@ -452,6 +459,7 @@
13B07FC11A68108700A75B9A /* main.m in Sources */,
7482404F246F9C0E009F68EA /* CovidShield.m in Sources */,
74B6941E245F15B20077B9DA /* ExposureNotification.m in Sources */,
A4E2F5EF258A84B50037F403 /* ENActivityHandling.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -549,7 +557,7 @@
"FB_SONARKIT_ENABLED=1",
);
INFOPLIST_FILE = "CovidShield/Info-debug.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.5;
IPHONEOS_DEPLOYMENT_TARGET = 12.5;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1;
OTHER_LDFLAGS = (
Expand Down Expand Up @@ -578,7 +586,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = CovidShield/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.5;
IPHONEOS_DEPLOYMENT_TARGET = 12.5;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1;
OTHER_LDFLAGS = (
Expand Down
12 changes: 8 additions & 4 deletions ios/CovidShield/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import "AppDelegate.h"

#import "ExposureNotification.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
Expand Down Expand Up @@ -101,10 +103,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
launchScreenView.frame = self.window.bounds;
rootView.loadingView = launchScreenView;
}

// [REQUIRED] Register BackgroundFetch
patchBGTaskSubmission();
[[TSBackgroundFetch sharedInstance] didFinishLaunching];

if ([ExposureNotification exposureNotificationSupportType] == ENSupportTypeVersion13dot5AndLater) {
// [REQUIRED] Register BackgroundFetch
patchBGTaskSubmission();
[[TSBackgroundFetch sharedInstance] didFinishLaunching];
}

// Define UNUserNotificationCenter
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
Expand Down
21 changes: 21 additions & 0 deletions ios/CovidShield/ENActivityHandling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// ENActivityHandling.h
// CovidShield
//
// Created by Clement Janin on 2020-12-16.
//

#import <Foundation/Foundation.h>
#import <ExposureNotification/ExposureNotification.h>

typedef void (^ENActivityHandler)(void);

NS_ASSUME_NONNULL_BEGIN

@interface ENManager (ENActivityHandling)

- (void)setLaunchActivityHandler:(ENActivityHandler)activityHandler;

@end

NS_ASSUME_NONNULL_END
16 changes: 16 additions & 0 deletions ios/CovidShield/ENActivityHandling.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ENActivityHandling.m
// CovidShield
//
// Created by Clement Janin on 2020-12-16.
//

#import "ENActivityHandling.h"

@implementation ENManager (ENActivityHandling)

- (void)setLaunchActivityHandler:(ENActivityHandler)activityHandler {
[self setValue:activityHandler forKey:@"activityHandler"];
}

@end
11 changes: 10 additions & 1 deletion ios/CovidShield/ExposureNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@
#import <React/RCTBridgeModule.h>
#import <ExposureNotification/ExposureNotification.h>

NS_ASSUME_NONNULL_BEGIN
typedef enum ExposureNotificationSupportType {
ENSupportTypeVersion12dot5,
ENSupportTypeVersion13dot5AndLater,
ENSupportTypeUnsupported
} ExposureNotificationSupportType;

NS_ASSUME_NONNULL_BEGIN

@interface ExposureNotification : NSObject<RCTBridgeModule>

@property (nonatomic, nullable, strong) ENManager *enManager;

+ (ExposureNotificationSupportType) exposureNotificationSupportType;

@end

NS_ASSUME_NONNULL_END
47 changes: 39 additions & 8 deletions ios/CovidShield/ExposureNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
//

#import "ExposureNotification.h"
#import <React/RCTConvert.h>

#import "ENActivityHandling.h"

#import <React/RCTConvert.h>
#import <TSBackgroundFetch/TSBackgroundFetch.h>

@interface ExposureNotification ()
@property (nonatomic) NSMutableArray *reportedSummaries;
Expand All @@ -34,13 +36,43 @@ - (void)invalidate
self.enManager = nil;
}

+ (ExposureNotificationSupportType) exposureNotificationSupportType {
if (@available(iOS 13.5, *)) {
return ENSupportTypeVersion13dot5AndLater;
} else if (NSClassFromString(@"ENManager") != nil) { // This check is specific to iOS 12.5
return ENSupportTypeVersion12dot5;
} else {
return ENSupportTypeUnsupported;
}
}

RCT_EXPORT_MODULE();

RCT_REMAP_METHOD(start, startWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
RCT_REMAP_METHOD(isExposureNotificationsFrameworkSupported, isExposureNotificationsFrameworkSupportedWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
if (self.enManager) return;
if ([ExposureNotification exposureNotificationSupportType] == ENSupportTypeUnsupported) {
reject(@"API_NOT_AVAILABLE", @"Exposure Notifications Framework is not supported", nil);
} else {
resolve(nil);
}
}

RCT_REMAP_METHOD(activate, activateWithCompletionHandler:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
if (self.enManager) {
resolve(nil);
return;
};

self.enManager = [ENManager new];

if ([ExposureNotification exposureNotificationSupportType] == ENSupportTypeVersion12dot5) {
[self.enManager setLaunchActivityHandler:^() {
TSBackgroundFetch *fetchManager = [TSBackgroundFetch sharedInstance];
[fetchManager performFetchWithCompletionHandler:^void(UIBackgroundFetchResult r) {}
applicationState:UIApplicationStateBackground];
}];
}

[self.enManager activateWithCompletionHandler:^(NSError * _Nullable error) {
if (error) {
reject([NSString stringWithFormat:@"%ld", (long)error.code], error.localizedDescription ,error);
Expand Down Expand Up @@ -154,7 +186,7 @@ - (void)invalidate
reject(@"API_NOT_ENABLED", [NSString stringWithFormat:@"Exposure Notification not authorized: %ld", ENManager.authorizationStatus], nil);
return;
}

ENExposureConfiguration *configuration = [ENExposureConfiguration new];

if (configDict[@"metadata"]) {
Expand All @@ -164,19 +196,19 @@ - (void)invalidate
if (configDict[@"minimumRiskScore"]) {
configuration.minimumRiskScore = [configDict[@"minimumRiskScore"] intValue];
}

if (configDict[@"attenuationDurationThresholds"]) {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 13.6) {
configuration.attenuationDurationThresholds = mapIntValues(configDict[@"attenuationDurationThresholds"]);
} else {
configuration.metadata = @{@"attenuationDurationThresholds": mapIntValues(configDict[@"attenuationDurationThresholds"])};
}
}

if (configDict[@"attenuationLevelValues"]) {
configuration.attenuationLevelValues = mapIntValues(configDict[@"attenuationLevelValues"]);
}

if (configDict[@"attenuationWeight"]) {
configuration.attenuationWeight = [configDict[@"attenuationWeight"] doubleValue];
}
Expand Down Expand Up @@ -227,4 +259,3 @@ - (void)invalidate
}

@end

3 changes: 1 addition & 2 deletions src/locale/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@
},
"FrameworkUnavailable": {
"Title": "Something went wrong",
"Body": "COVID Alert is not supported by your phone’s operating system.\n\nMake sure your operating system is up to date.\n\nIf you have an Android phone, try updating your Google Play Services.",
"CTA": "Get Help"
"Body": "To use COVID Alert, please update your operating system."
},
"UnknownProblem": {
"Title": "Something went wrong",
Expand Down
Loading