Session 在IOS中的异步调用中转换Base64字符串

Session 在IOS中的异步调用中转换Base64字符串,session,ios7,asynchronous,base64,Session,Ios7,Asynchronous,Base64,我有一个NSURLSessionDataTask,我从completionHandler获得一个Base64字符串。我在使用NS编码库将其转换回纯文本时遇到了困难,即使在查找了各种帖子之后也是如此 ,, , 来自completionHandler^(数据)=INSNYWN0AW9UJZNDGVZDCSICDPBNBB1DCC6J3RLC3QNFSI的字符串= 用于尝试和解码的代码: NSString *baseString =[data base64EncodedStringWithOpti

我有一个NSURLSessionDataTask,我从completionHandler获得一个Base64字符串。我在使用NS编码库将其转换回纯文本时遇到了困难,即使在查找了各种帖子之后也是如此

,, ,

来自completionHandler^(数据)=INSNYWN0AW9UJZNDGVZDCSICDPBNBB1DCC6J3RLC3QNFSI的字符串=

用于尝试和解码的代码:

NSString *baseString =[data base64EncodedStringWithOptions:NSDataBase64Encoding76CharacterLineLength];
我希望有人能把我引向正确的方向。谢谢

全功能-灵感来源于():


}

数据
包含base64编码字符串(表示表示某些原始对象的数据)。因此,您需要将
数据
转换为实际的
NSData
,表示最初编码的数据

基本上,您需要反转原始编码步骤

如果您使用的是iOS 7或更高版本,您可以执行以下操作:

NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:urlRequest
    completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        //NSLog(@"Response:%@ %@\n", response, error);
        if (data) {
            NSData *originalData = [[NSData alloc] initWithBase64EncodedData:data options:0];
            // Do something with the decoded data
        } else {
            NSLog(@"error = %@", error);
        }
}];

显示更多代码以提供更多上下文。rmaddy希望更新有帮助,谢谢。
NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:urlRequest
    completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        //NSLog(@"Response:%@ %@\n", response, error);
        if (data) {
            NSData *originalData = [[NSData alloc] initWithBase64EncodedData:data options:0];
            // Do something with the decoded data
        } else {
            NSLog(@"error = %@", error);
        }
}];