0
您好,我想实现amazone提供的snspush通知服务。 我为 安装荚在podfile我写 荚“AWSSNS” 是 吊舱安装后AWSSNS(Amazone推送通知),应用程序崩溃
然后,我实现像这个代码
当我运行的应用程序,有崩溃与以下日志
****由于未捕获异常'NSInternalInconsistencyException',终止应用程序,原因:'服务配置是nil
。您需要配置Info.plist
或使用该方法之前设置defaultServiceConfiguration
。“*
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIMutableUserNotificationCategory *messageCategory = [[UIMutableUserNotificationCategory alloc] init];
messageCategory.identifier = @"ShareAction";
UIMutableUserNotificationAction *notificationAction = [[UIMutableUserNotificationAction alloc] init];
notificationAction.identifier = @"ShareAction";
notificationAction.title = @"Share";
notificationAction.activationMode = UIUserNotificationActivationModeForeground;
notificationAction.authenticationRequired = YES;
notificationAction.destructive = NO;
[messageCategory setActions:@[notificationAction] forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:messageCategory];
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:categories];
[[UIApplication sharedApplication] registerForRemoteNotifications];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{
NSString *deviceTokenString = [[[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"deviceTokenString: %@", deviceTokenString);
[[NSUserDefaults standardUserDefaults] setObject:deviceTokenString forKey:@"deviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
AWSSNS *sns = [AWSSNS defaultSNS];
AWSSNSCreatePlatformEndpointInput *request = [AWSSNSCreatePlatformEndpointInput new];
request.token = deviceTokenString;
request.platformApplicationArn = SNSPlatformApplicationArn;
[[sns createPlatformEndpoint:request] continueWithBlock:^id(AWSTask *task) {
if (task.error != nil) {
NSLog(@"Error: %@",task.error);
} else {
AWSSNSCreateEndpointResponse *createEndPointResponse = task.result;
NSLog(@"endpointArn: %@",createEndPointResponse);
[[NSUserDefaults standardUserDefaults] setObject:createEndPointResponse.endpointArn forKey:@"endpointArn"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
return nil;
}];
}
请帮助,如果任何人知道。
其同样,打印日志作为终止应用程序由于未捕获的异常“NSInternalInconsistencyException”,理由是:“服务配置为零。在使用此方法之前,您需要配置Info.plist或设置defaultServiceConfiguration。' – user2856484