iOS AWS SNS:客户端如何确认 SNS 主题订阅?
iOS AWS SNS: How does client confirm SNS Topic subscription?
在设备注册远程通知后(在 application:didRegisterForRemoteNotificationsWithDeviceToken)我是:
- 正在使用设备的令牌创建平台终结点。
- 正在订阅主题。
- 正在尝试*确认主题订阅
我卡在了上面列表中的第 3 步。我不知道如何获取创建 "AWSSNSConfirmSubscriptionInput" 对象所需的令牌以传递给 "confirmSubscription"。
我应该注意到,尽管订阅尚未确认,但我能够从该主题发送 APN。这不是iOS(应用程序协议)上下文中的必要步骤吗?
documentation 声明如下:
To actually create a subscription, the endpoint owner must call the ConfirmSubscription action with the token from the confirmation message. Confirmation tokens are valid for three days.
我不知道如何获得执行 "ConfirmSubscription" 操作所需的 "token"。 "Subscribe" 操作结果的类型为 "AWSSNSSubscribeResponse",它只有一个 属性、“subscriptionArn”,似乎不包含包含令牌的 "confirmation message"。那么如何获得这个token呢?
这是我的 application: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
如果服务能够立即创建订阅(无需端点所有者确认)。对于移动设备,应该是这样。
附带说明一下,在注册设备时,您应该遵循此中的伪代码 blog post. AWS Mobile Hub 可以生成一个参考实现,用于注册设备并使用推荐的工作流程订阅主题。
在设备注册远程通知后(在 application:didRegisterForRemoteNotificationsWithDeviceToken)我是:
- 正在使用设备的令牌创建平台终结点。
- 正在订阅主题。
- 正在尝试*确认主题订阅
我卡在了上面列表中的第 3 步。我不知道如何获取创建 "AWSSNSConfirmSubscriptionInput" 对象所需的令牌以传递给 "confirmSubscription"。
我应该注意到,尽管订阅尚未确认,但我能够从该主题发送 APN。这不是iOS(应用程序协议)上下文中的必要步骤吗?
documentation 声明如下:
To actually create a subscription, the endpoint owner must call the ConfirmSubscription action with the token from the confirmation message. Confirmation tokens are valid for three days.
我不知道如何获得执行 "ConfirmSubscription" 操作所需的 "token"。 "Subscribe" 操作结果的类型为 "AWSSNSSubscribeResponse",它只有一个 属性、“subscriptionArn”,似乎不包含包含令牌的 "confirmation message"。那么如何获得这个token呢?
这是我的 application: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
如果服务能够立即创建订阅(无需端点所有者确认)。对于移动设备,应该是这样。
附带说明一下,在注册设备时,您应该遵循此中的伪代码 blog post. AWS Mobile Hub 可以生成一个参考实现,用于注册设备并使用推荐的工作流程订阅主题。