AWS iOS SDK,服务配置为`nil

Posted

技术标签:

【中文标题】AWS iOS SDK,服务配置为`nil【英文标题】:AWS iOS SDK, The service configuration is `nil 【发布时间】:2018-05-02 05:20:36 【问题描述】:

我需要在 AWS 中为 SNS 推送通知创建一个平台端点。

为了注册设备以获取推送通知,我需要将设备 ID 发送到 SNS,我没有使用 cognito,我想使用手机上的 AWS SDK 上传令牌:

AWSSNSCreatePlatformEndpointInput

当我尝试注册时:

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
NSLog(@"deviceToken: %@", deviceToken);

/* This is the code to actually register the device with Amazon SNS Mobile Push based on the token received */

NSString * myArn = @"arn:aws:sns:us-east-1:123456789123:app/APNS_SANDBOX/AmazonMobilePushExample";

NSLog( @"Submit the device token [%@] to SNS to receive notifications.", [self deviceTokenAsString:deviceToken] );

AWSSNSCreatePlatformEndpointInput *platformEndpointRequest = [AWSSNSCreatePlatformEndpointInput new];
platformEndpointRequest.customUserData = @"MyUserID;iPhone5";
platformEndpointRequest.token = [self deviceTokenAsString:deviceToken];
platformEndpointRequest.platformApplicationArn = myArn;


//THIS LINE CRASHING
AWSSNS *snsManager = [AWSSNS defaultSNS];


//    [snsManager createPlatformEndpoint:platformEndpointRequest];

但我收到崩溃错误:

'服务配置为nil。使用此方法前需要配置awsconfiguration.jsonInfo.plist或设置defaultServiceConfiguration。'

那么,如何在没有 cognito 的情况下直接配置我的方法的 plist?

干杯

【问题讨论】:

【参考方案1】:

需要的是设置

AWSServiceManager 默认服务管理器

如下:

- (void)awsStartWithDeviceToken:(NSData *)deviceToken 

// Set the log level
[AWSLogger defaultLogger].logLevel = AWSLogLevelVerbose;

// Login
AWSStaticCredentialsProvider *credentialsProvider = [[AWSStaticCredentialsProvider alloc]
                                                     initWithAccessKey:@"AKIAIxxxYYYA"
                                                     secretKey:@"Tx0vhKv1xMaaabbbbccccM5+3R9lEitw2Hzw"];


AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc]
                                          initWithRegion:AWSRegionAPSoutheast2
                                          credentialsProvider:credentialsProvider];

    [AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

// Create SNS Client

AWSSNS *snsManager = [AWSSNS defaultSNS];


/* This is the code to actually register the device with Amazon SNS Mobile Push based on the token received. */
AWSSNSCreatePlatformEndpointInput* platformEndpointRequest = [AWSSNSCreatePlatformEndpointInput new];
platformEndpointRequest.customUserData = @"kUniqueID";     // It could be anything.
platformEndpointRequest.token =  [self deviceTokenAsString:deviceToken];         // Device Token No for APNS
platformEndpointRequest.platformApplicationArn = @"arn:aws:sns:ap-southeast-2:86434343191:app/APNS_SANDBOX/ios_lambada";



[snsManager createPlatformEndpoint:platformEndpointRequest completionHandler:^(AWSSNSCreateEndpointResponse * _Nullable response, NSError * _Nullable error) 
    NSLog(@"errore : %@", error);
];


【讨论】:

以上是关于AWS iOS SDK,服务配置为`nil的主要内容,如果未能解决你的问题,请参考以下文章

AWS iOS SDK Cognito 开发人员身份验证 (Swift)

将数组传递给 ios sdk 中的 .net webservice

IOS Swift Amazon S3 传输实用程序 - nil 与预期的参数类型 nsurl 不兼容

在 iOS 4.2 SDK 中返回 NSString 的函数总是返回 nil

Spotify iOS SDK 返回 SPTListPage.items 返回 nil

使用 AWS SSO 时 AWS Java SDK 未找到配置文件