in Example/AmazonFreeRTOSDemo/AmazonFreeRTOSDemo/DevicesViewController.swift [132:168]
func attachPrincipalPolicy() {
// get the AWS Cognito Identity
AWSMobileClient.default().getIdentityId().continueWith { task -> Any? in
if let error = task.error {
DispatchQueue.main.async {
Alertift.alert(title: NSLocalizedString("Error", comment: String()), message: error.localizedDescription)
.action(.default(NSLocalizedString("OK", comment: String())))
.show(on: self)
}
return task
}
guard let attachPrincipalPolicyRequest = AWSIoTAttachPrincipalPolicyRequest(), let principal = task.result else {
return task
}
// The AWS IoT Policy
attachPrincipalPolicyRequest.policyName = AmazonConstants.AWS.iotPolicyName
// The AWS Cognito Identity
attachPrincipalPolicyRequest.principal = String(principal)
AWSIoT.default().attachPrincipalPolicy(attachPrincipalPolicyRequest, completionHandler: { error in
if let error = error {
DispatchQueue.main.async {
Alertift.alert(title: NSLocalizedString("Error", comment: String()), message: error.localizedDescription)
.action(.default(NSLocalizedString("OK", comment: String())))
.show(on: self)
}
}
})
return task
}
}