我正在使用Amazon Web Services的简单通知服务(SNS)开发iOS应用程序.此时,应用程序将设备注册到主题,并可以接收推送通知,这些通知将发布到主题.可以将设备订阅到许多主题.
现在我正在尝试从特定主题取消订阅设备,但SNSUnsubscribeRequest需要SubscriptionARN.我试图使用设备中的EndpointARN,但似乎我要为EndpointARN和TopicARN的组合使用额外的SubscriptionARN.我如何获得此ARN?
在这篇文章中:你如何获得订阅的arn?他们要求提供整个订户列表,并将每个EndpointARN与设备的EndpointARN进行比较.这不是我想的正确方法.
订阅主题
// Check if endpoint exist
if (endpointARN == nil) {
dispatch_async(dispatch_get_main_queue(), ^{
[[self universalAlertsWithTitle:@"endpointARN not found!" andMessage:@"Please create an endpoint for this device before subscribe to topic"] show];
});
return NO;
}
// Create topic if not exist
NSString *topicARN = [self findTopicARNFor:topic];
if (!topicARN) {
[self createTopic:topic];
topicARN = [self findTopicARNFor:topic];
}
// Subscribe to topic if exist
if (topicARN) {
SNSSubscribeRequest *subscribeRequest = [[SNSSubscribeRequest alloc] initWithTopicArn:topicARN andProtocol:@"application" andEndpoint:endpointARN];
SNSSubscribeResponse *subscribeResponse …Run Code Online (Sandbox Code Playgroud) 我已经为我的位置搜索委托构建了一个建议列表,它总是在顶部有一个项目,可以将用户推送到新页面。在这个新页面上,用户可以选择地图上的位置并提交或返回搜索页面。如果用户提交位置,我想关闭带有所选位置的基础位置搜索委托作为结果。
对于这种行为,我在无状态建议列表小部件中使用回调,但在 onMapTapped 回调的情况下,应用程序会引发异常:
class LocationSearchDelegate extends SearchDelegate<Location> {
// ...
@override
Widget buildSuggestions(BuildContext context) {
return _SuggestionList(
query: query,
onSelected: (Location suggestion) {
result = suggestion;
close(context, result);
},
onMapTapped: (Location location) {
result = location;
close(context, result); // <- Throws exception
},
);
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
例外:
Looking up a deactivated widget's ancestor is unsafe.
At this point the state of the widget's element tree is no longer stable. To safely refer to a widget's ancestor in …Run Code Online (Sandbox Code Playgroud)