我需要在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.json
,Info.plist
或设置defaultServiceConfiguration
。
那么,如何使用cognito直接配置我的方法的plist?
干杯
答案 0 :(得分:0)
需要的是设置
AWSServiceManager defaultServiceManager
如下:
- (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);
}];
}