AWSプッシュ通知

エンドポイントANRを取得します。

import AWSSNS

// ...

func application(application: UIApplication,
                 didFinishLauchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // ...
    let settings =
    UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert],
                               categories: nil)
    application.registerUserNotificationSetting(settings)
    application.registerForRemoteNotifications()
    return true
}

    func application(application: UIApplication,
                     didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData){
        let deviceTokenString = "¥(deviceToken)"
        .stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString:"<>"))
        .stringByReplacingOccurrencesOfString(" ", withString: "")
        
        let credentialsProvider =
        AWSCognitoCredentialsProvider(regionType: .USEast1,
                                      identityPoolId: "us-east-1:")
        
        let serviceConfiguration =
        AWSServiceConfiguration(region: .USEast1,
                                credentialsProvider: credentialProvider)
        AWSServiceManager.defaultServiceManager().defaultServiceConfiguration =
        serviceConfiguration
        
        let createPlatformEndpointInput = AWSSNSCreatePlatformEndpointInput()
        createPlatformEndpointInput.platformApplicationArn =
        "arn:aws:sns:us-east-1::app/APNS_SANDBOX/Share"
        createPlatformEndpointInput.token = deviceTokenString
        AWSSNS.defaultSNS().createPlatformEndpoint(createPlatformEndpointInput)
        .continueWithSuccessBlock({(task) -> AnyObject! in
            guard let createEndpointResponse =
            task.result as? AWSSNSCreateEndpointResponse else{
                return task
            }
            let subscribeInput = AWSSNSSubscribeInput()
            subscribeInput.protocols = "application"
            subscriptInput.topicArn =
            "arn:aws:sns:us-east-1::share-users"
            subscribeInput.endpoint = createEndpointResponse.endpointArn
            return AWSSNS.defaultSNS.subscribe(subscribeInput)
        })
    }