__NSmallocblock__亚马逊AWS Dynamo错误 - iOS

时间:2015-02-18 16:26:44

标签: ios amazon-web-services amazon-dynamodb

我遇到Dynamo AWS的问题,我试图从数据库中获取ID并随机获取内存分配错误。 以下是我用来获取信息的代码:

AWSCognitoCredentialsProvider *credentialsProvider = [AWSCognitoCredentialsProvider credentialsWithRegionType:AWSRegionUSEast1
                                                                                                    accountId:AWSAccountID
                                                                                               identityPoolId:CognitoPoolID
                                                                                                unauthRoleArn:CognitoRoleUnauth
                                                                                                  authRoleArn:CognitoRoleAuth];

//Set the server connection to AWSRegionUSEast1 with the credentials
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1
                                                                      credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
[AWSLogger defaultLogger].logLevel = AWSLogLevelVerbose;

NSString *token = FBSession.activeSession.accessTokenData.accessToken;
credentialsProvider.logins = @{ @(AWSCognitoLoginProviderKeyFacebook): token };

//Access the users table with the Facebook ID.
DDBTableRow *tableRow = [DDBTableRow new];
tableRow.UsersHash1ID = [defaults objectForKey:@"UserID"];
tableRow.UsersRange1 = [defaults objectForKey:@"UserID"];

AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];

//Create a load connection to the AWS Dynamo database to find out if the user already exists
[[dynamoDBObjectMapper load:[DDBTableRow class]
                    hashKey:tableRow.UsersHash1ID
                   rangeKey:tableRow.UsersRange1] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
    if (!task.error) {
        DDBTableRow *tableRow = task.result;
        //TODO: Crashes
        if (tableRow.UsersHash1ID == nil) {// if the user does not exist.
            [self firstPlay];
        } else {
            [self SecondPlay]; //If the user exist already in the database.
        }
    } else { //Error handling
        NSLog(@"Error: [%@]", task.error);
        //TODO: handle the connection

        HUD.textLabel.text = @"Error Connecting to Database";

        [HUD dismissAfterDelay:5.0];

    }
    return nil;
}];

这是我收到的错误: Image Error

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

- load:hashKey:rangeKey:是一种异步方法。这意味着您创建的第一个tableRow对象可以在- load:hashKey:rangeKey:完成执行之前解除分配。

您可以重写此部分

[dynamoDBObjectMapper load:[DDBTableRow class]
                   hashKey:tableRow.UsersHash1ID
                  rangeKey:tableRow.UsersRange1]

类似

[dynamoDBObjectMapper load:[DDBTableRow class]
                   hashKey:[defaults objectForKey:@"UserID"]
                  rangeKey:[defaults objectForKey:@"UserID"]]

(您为散列键和范围键设置了相同的值。您应该确保这是您真正想要的。)

如果它没有解决问题,您应该启用NSZombie并查看取消分配的对象。