所以我downloaded the attached project并将代码复制到我的项目。这就是我所做的。
我用正确的值替换了以下内容。我在亚马逊认知中创建了一个USERPOOL
来获取这些值。
NSString *const CognitoIdentityUserPoolId = @"XXX";
NSString *const CognitoIdentityUserPoolAppClientId = @"XXX";
NSString *const CognitoIdentityUserPoolAppClientSecret = @"XXX";
我的问题是,一旦didFinishLaunchingWithOptions
被执行,它将启动委托方法-(id<AWSCognitoIdentityPasswordAuthentication>) startPasswordAuthentication
。但是,在我的情况下,它不能解决这个问题吗?
AppDelegate.h
看起来像这样
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "AWSCognitoIdentityProvider.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate,AWSCognitoIdentityInteractiveAuthenticationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
@end
AppDelegate.m
看起来像这样
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//setup logging
[AWSLogger defaultLogger].logLevel = AWSLogLevelVerbose;
//setup service config
AWSServiceConfiguration *serviceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil];
if([@"YOUR_USER_POOL_ID" isEqualToString:CognitoIdentityUserPoolId]){
[[[UIAlertView alloc] initWithTitle:@"Invalid Configuration"
message:@"Please configure user pool constants in Constants.m"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil] show];
}
//create a pool
AWSCognitoIdentityUserPoolConfiguration *configuration = [[AWSCognitoIdentityUserPoolConfiguration alloc] initWithClientId:CognitoIdentityUserPoolAppClientId clientSecret:CognitoIdentityUserPoolAppClientSecret poolId:CognitoIdentityUserPoolId];
[AWSCognitoIdentityUserPool registerCognitoIdentityUserPoolWithConfiguration:serviceConfiguration userPoolConfiguration:configuration forKey:@"UserPool"];
AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:@"UserPool"];
//self.storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
pool.delegate = self;
return YES;
}
-(id<AWSCognitoIdentityPasswordAuthentication>) startPasswordAuthentication{
NSLog(@"Came into this method");
return _signInViewController;
}
答案 0 :(得分:0)
通过禁用情节提要,您已删除调用以获取用户的会话,因此不会调用身份验证委托方法。在这段代码中放置一些这样的代码会得到一个会话并触发auth流程:
[[pool currentUser] getSession];