[英]iOS AWS SNS: How does client confirm SNS Topic subscription?
After a device registers for remote notifications (in application:didRegisterForRemoteNotificationsWithDeviceToken ) I am: 设备注册了远程通知后(在application:didRegisterForRemoteNotificationsWithDeviceToken中 ),我是:
I am stuck on step 3 from the above list. 我停留在上述列表的第3步。 I can't figure out how to get the token needed to create a "AWSSNSConfirmSubscriptionInput" object to pass to "confirmSubscription".
我无法弄清楚如何获取创建“ AWSSNSConfirmSubscriptionInput”对象传递给“ confirmSubscription”所需的令牌。
I should note that I am able to send APNs from the topic despite the fact that the subscription is not confirmed. 我应该注意,尽管未确认订阅,但我仍可以从该主题发送APN。 Is this not a necessary step in the context of iOS (application protocol)?
在iOS(应用协议)的上下文中这不是必需的步骤吗?
The documentation states following: 该文档指出以下内容:
To actually create a subscription, the endpoint owner must call the ConfirmSubscription action with the token from the confirmation message.
要实际创建订阅,端点所有者必须使用来自确认消息的令牌来调用ConfirmSubscription操作。 Confirmation tokens are valid for three days.
确认令牌有效期为三天。
I can't figure out how to obtain the "token" necessary to perform the "ConfirmSubscription" action. 我不知道如何获取执行“ ConfirmSubscription”操作所需的“令牌”。 The "Subscribe" action result is of type "AWSSNSSubscribeResponse" which only has a single propery, " subscriptionArn" and does not appear to contain a "confirmation message" including a token.
“订阅”操作结果的类型为“ AWSSNSSubscribeResponse”,它只有一个属性“ subscriptionArn”,并且似乎不包含包含令牌的“确认消息”。 So how do I obtain this token?
那么如何获得此令牌?
Here is the body of my application:didRegisterForRemoteNotificationsWithDeviceToken delegate method: 这是我的应用程序的主体:didRegisterForRemoteNotificationsWithDeviceToken委托方法:
sns.createPlatformEndpoint(createPlatformEndPointInput).continueWithBlock { (task:AWSTask!) in
if let error = task.error{
XCGLogger.defaultInstance().error("Platform endpoint creation error: \(error)")
return nil
}
let result = task.result as! AWSSNSCreateEndpointResponse
let subscribeInput = AWSSNSSubscribeInput()
subscribeInput.topicArn = "arn:aws:sns:us-west-2:xxx:topicname"
subscribeInput.endpoint = result.endpointArn
subscribeInput.protocols = "application"
sns.subscribe(subscribeInput).continueWithBlock({ (task:AWSTask!) in
if let subError = task.error{
XCGLogger.defaultInstance().error("Topic Subscription Error: \(subError)")
return nil
}
let subscribeResult = task.result as! AWSSNSSubscribeResponse
XCGLogger.defaultInstance().debug("Subscription result: \(subscribeResult)")
let subscriptionConfirmInput = AWSSNSConfirmSubscriptionInput()
subscriptionConfirmInput.token = ?? //How do I get this??
subscriptionConfirmInput.topicArn = "arn:aws:sns:xxx:myTopic"
sns.confirmSubscription(subscriptionConfirmInput).continueWithBlock({ (task:AWSTask!) in
if let error = task.error{
XCGLogger.defaultInstance().error("Subscription Confirmation Error: \(error)")
}
return nil
})
return nil
})
return nil
}
Subscribe
returns SubscriptionArn
if the service was able to create a subscription immediately (without requiring endpoint owner confirmation). 如果服务能够立即创建订阅(不需要端点所有者确认),则
Subscribe
返回SubscriptionArn
。 For mobile devices, this should be the case. 对于移动设备,情况应该如此。
As a side note, when registering the device, you should follow the pseudo code in this blog post . 另外,注册设备时,请遵循此博客文章中的伪代码。 AWS Mobile Hub can produce a reference implementation for registering the device and subscribing to a topic using the recommended workflow as well.
AWS Mobile Hub还可生成参考实施,以使用推荐的工作流程注册设备并订阅主题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.