首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过Amazon匿名TVM注册用于Amazon (APNS)的iOS设备

通过Amazon匿名TVM注册用于Amazon (APNS)的iOS设备
EN

Stack Overflow用户
提问于 2014-04-21 21:41:32
回答 1查看 1K关注 0票数 0

类似的问题在StackOverflow上也出现过几次,但亚马逊的SNS却没有解决方案。

这份文件声明,为Amazon ( an )注册设备可以通过匿名令牌供应商机器完成。这份文件为部署提供了一个模板,我已经使用过该模板,然后此代码示例指定了一个演示其使用的iOS客户端。但是,没有在模板配置源或iOS客户机示例中看到TVM是如何链接到SNS应用程序以创建设备条目(称为端点)的。有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-22 14:52:40

事实证明,引用是链接客户端。解决办法如下:

代码语言:javascript
复制
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];
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23206521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档