在iOS上订阅Amazon Mobile Push端点

时间:2014-06-12 15:19:26

标签: ios objective-c amazon-web-services

我在以编程方式将我的应用程序订阅端点连接到亚马逊的移动推送服务时遇到了麻烦。我一直得到" SNSInvalidParameterException"。下面是我用来运行我的iOS应用程序的设备订阅的代码。

-(NSString*)deviceTokenAsString:(NSData*)deviceTokenData {
NSString *rawDeviceTring = [NSString stringWithFormat:@"%@", deviceTokenData];
NSString *noSpaces = [rawDeviceTring stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *tmp1 = [noSpaces stringByReplacingOccurrencesOfString:@"<" withString:@""];

return [tmp1 stringByReplacingOccurrencesOfString:@">" withString:@""];
}

//Callback after the app registers for push
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
//Amazon
AmazonSNSClient *snsClient = [[AmazonSNSClient alloc] initWithAccessKey:@"myAccessKey" withSecretKey:@"mySecretKey"];


SNSCreatePlatformEndpointRequest *endpointRequest = [SNSCreatePlatformEndpointRequest new];
endpointRequest.token = [self deviceTokenAsString:newDeviceToken];
endpointRequest.platformApplicationArn = @"myAppARN";
[snsClient createPlatformEndpoint:endpointRequest];
}

程序总是在[snsClient createPlatformEndpoint:endpointRequest]行崩溃。我确实拥有应用内推送通知设置的权限。我唯一可以想象的是错误是appARN不正确或我输入的令牌不正确。但是,我正在使用的ARN是直接从我的亚马逊网络控制台上复制粘贴的,我用来创建令牌作为NSString的公式是这个网站上的多个其他帖子显示为人们工作的东西。任何帮助将非常感激。

1 个答案:

答案 0 :(得分:0)

你错过了下一行:(在&#34之后; AmazonSNSClient * snsClient =&#34; ......

snsClient.endpoint = [AmazonEndpoints snsEndpoint:/ your_aws_AmazonRegion /];

之后 - 一切都很完美!