Skip to content

Instantly share code, notes, and snippets.

@Thunderbird7
Created February 3, 2016 17:37
Show Gist options
  • Save Thunderbird7/ed90a54574dfd35597df to your computer and use it in GitHub Desktop.
Save Thunderbird7/ed90a54574dfd35597df to your computer and use it in GitHub Desktop.
// ARN Endpoint
// For Amazon SNS
NSString *myARN = @"arn:aws:sns:ap-southeast-1:570761336625:app/APNS_SANDBOX/Airportthai";
AWSSNSCreatePlatformEndpointInput *platformEndpointRequest = [AWSSNSCreatePlatformEndpointInput new];
[platformEndpointRequest setCustomUserData:@"custom user data เช่นระบบ iOS version, Device Version อะไรก็ได้"];
[platformEndpointRequest setToken:[self deviceTokenAsString:deviceToken]]; //แปลง device token ให้เป็น string ก่อนนะ
[platformEndpointRequest setPlatformApplicationArn:myARN];
AWSSNS *snsManager = [AWSSNS defaultSNS];
[snsManager createPlatformEndpoint:platformEndpointRequest completionHandler:^(AWSSNSCreateEndpointResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"AWSSNS Error: %@", error);
} else {
NSLog(@"AWSSNS endpoint ARN: %@", response.endpointArn);
//TODO: Subcript to topic
AWSSNSSubscribeInput *subscribeRequest = [AWSSNSSubscribeInput new];
[subscribeRequest setEndpoint:response.endpointArn];
[subscribeRequest setProtocols:@"application"];
[subscribeRequest setTopicArn:@"arn:aws:sns:ap-southeast-1:570761336625:AOT-Promotion"];
[snsManager subscribe:subscribeRequest completionHandler:^(AWSSNSSubscribeResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"AWSSNS Subscribe Error: %@", error);
} else {
NSLog(@"AWSSNS Subscribe Success: %@", response);
}
}];
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment