|
|
|
@ -13,6 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele |
|
|
|
|
private let SNSPlatformApplicationArn = "arn:aws:sns:us-west-2:400248756644:app/APNS/AlphaWallet-iOS" |
|
|
|
|
private let SNSPlatformApplicationArnSANDBOX = "arn:aws:sns:us-west-2:400248756644:app/APNS_SANDBOX/AlphaWallet-testing" |
|
|
|
|
private let identityPoolId = "us-west-2:42f7f376-9a3f-412e-8c15-703b5d50b4e2" |
|
|
|
|
private let SNSTopicEndpoint = "arn:aws:sns:us-west-2:400248756644:security" |
|
|
|
|
//This is separate coordinator for the protection of the sensitive information. |
|
|
|
|
private lazy var protectionCoordinator: ProtectionCoordinator = { |
|
|
|
|
return ProtectionCoordinator() |
|
|
|
@ -35,20 +36,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele |
|
|
|
|
|
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func cognitoRegistration() |
|
|
|
|
{ |
|
|
|
|
// Override point for customization after application launch. |
|
|
|
|
/// Setup AWS Cognito credentials |
|
|
|
|
// Initialize the Amazon Cognito credentials provider |
|
|
|
|
// let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USWest2, |
|
|
|
|
// identityPoolId: identityPoolId) |
|
|
|
|
// let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialsProvider) |
|
|
|
|
// AWSServiceManager.default().defaultServiceConfiguration = configuration |
|
|
|
|
// let defaultServiceConfiguration = AWSServiceConfiguration( |
|
|
|
|
// region: AWSRegionType.USWest2, credentialsProvider: credentialsProvider) |
|
|
|
|
// AWSServiceManager.default().defaultServiceConfiguration = defaultServiceConfiguration |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func applicationWillResignActive(_ application: UIApplication) { |
|
|
|
|
protectionCoordinator.applicationWillResignActive() |
|
|
|
@ -123,12 +110,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele |
|
|
|
|
if let endpointArnForSNS = createEndpointResponse.endpointArn { |
|
|
|
|
print("endpointArn: \(endpointArnForSNS)") |
|
|
|
|
UserDefaults.standard.set(endpointArnForSNS, forKey: "endpointArnForSNS") |
|
|
|
|
//every user should subscribe to the security topic |
|
|
|
|
self.subscribeToSecurityTopicSNS(token: token) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func subscribeToSecurityTopicSNS(token: String) { |
|
|
|
|
let sns = AWSSNS.default() |
|
|
|
|
guard let endpointRequest = AWSSNSCreatePlatformEndpointInput() else { return } |
|
|
|
|
endpointRequest.platformApplicationArn = SNSPlatformApplicationArn |
|
|
|
|
endpointRequest.token = token |
|
|
|
|
|
|
|
|
|
sns.createPlatformEndpoint(endpointRequest).continueWith() { task in |
|
|
|
|
guard let response: AWSSNSCreateEndpointResponse = task.result else { return nil } |
|
|
|
|
guard let subscribeRequest = AWSSNSSubscribeInput() else { return nil } |
|
|
|
|
subscribeRequest.endpoint = response.endpointArn |
|
|
|
|
subscribeRequest.protocols = "application" |
|
|
|
|
subscribeRequest.topicArn = self.SNSTopicEndpoint |
|
|
|
|
return sns.subscribe(subscribeRequest) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//TODO Handle SNS errors |
|
|
|
|
func application(_ application: UIApplication, |
|
|
|
|
didFailToRegisterForRemoteNotificationsWithError error: Error) { |
|
|
|
|