类似的问题在StackOverflow上也出现过几次,但亚马逊的SNS却没有解决方案。
这份文件声明,为Amazon ( an )注册设备可以通过匿名令牌供应商机器完成。这份文件为部署提供了一个模板,我已经使用过该模板,然后此代码示例指定了一个演示其使用的iOS客户端。但是,没有在模板配置源或iOS客户机示例中看到TVM是如何链接到SNS应用程序以创建设备条目(称为端点)的。有什么想法吗?
发布于 2014-04-22 14:52:40
事实证明,引用是链接客户端。解决办法如下:
Include:
AWSRuntime.framework
AWSSecurityTokenService.framework
AWSSNS.framework
#define SNS_PLATFORM_APPLICATION_ARN @"Insert ARN here"
#define TOKEN_VENDING_MACHINE_URL @"Insert vending machine url, found in output tab"
#define USE_SSL 1
#pragma mark - Amazon TVM
+ (void)initSNS
{
AmazonCredentials *credentials = [AmazonKeyChainWrapper getCredentialsFromKeyChain];
sns = [[AmazonSNSClient alloc] initWithCredentials:credentials];
sns.endpoint = [AmazonEndpoints snsEndpoint:US_WEST_2];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
}
+ (AmazonTVMClient *)tvm
{
if (tvm == nil) {
tvm = [[AmazonTVMClient alloc] initWithEndpoint:TOKEN_VENDING_MACHINE_URL useSSL:USE_SSL];
}
return tvm;
}
+ (bool)hasCredentials
{
return ![TOKEN_VENDING_MACHINE_URL isEqualToString:@"CHANGE ME"];
}
+ (Response *)validateCredentials
{
Response *ableToGetToken = [[Response alloc] initWithCode:200 andMessage:@"OK"];
if ([AmazonKeyChainWrapper areCredentialsExpired]) {
@synchronized(self)
{
if ([AmazonKeyChainWrapper areCredentialsExpired]) {
ableToGetToken = [[self tvm] anonymousRegister];
if ( [ableToGetToken wasSuccessful])
{
ableToGetToken = [[self tvm] getToken];
if ( [ableToGetToken wasSuccessful])
{
[AppDelegate initSNS];
}
}
}
}
}
else
{
[AppDelegate initSNS];
}
return ableToGetToken;
}
#pragma mark - Push Notification
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
application.applicationIconBadgeNumber = 0;
NSString *msg = [NSString stringWithFormat:@"%@", userInfo];
NSLog( @"%@", msg );
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Message Received" message:[NSString stringWithFormat:@"%@", msg]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
-(NSString*)deviceTokenAsString:(NSData*)deviceTokenData
{
NSString *rawDeviceTring = [NSString stringWithFormat:@"%@", deviceTokenData];
NSString *noSpaces = [rawDeviceTring stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *tmp1 = [noSpaces stringByReplacingOccurrencesOfString:@"<" withString:@""];
return [tmp1 stringByReplacingOccurrencesOfString:@">" withString:@""];
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog( @"Submit the device token [%@] to SNS to receive notifications.", deviceToken );
SNSCreatePlatformEndpointRequest *platformEndpointRequest = [SNSCreatePlatformEndpointRequest new];
platformEndpointRequest.customUserData = @"Here's the custom data for the user.";
platformEndpointRequest.token = [self deviceTokenAsString:deviceToken];
platformEndpointRequest.platformApplicationArn = SNS_PLATFORM_APPLICATION_ARN;
[sns createPlatformEndpoint:platformEndpointRequest];
}https://stackoverflow.com/questions/23206521
复制相似问题