首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法识别iOS OSStatus代码

无法识别iOS OSStatus代码
EN

Stack Overflow用户
提问于 2013-12-28 16:54:46
回答 1查看 5.8K关注 0票数 2

在iOS应用程序中,我有一个非常奇怪的行为。我从iOS 6转到了iOS 7,在iOS 6中,一切都很完美。

代码语言:javascript
复制
- (NSMutableDictionary *)newSearchDictionary:(NSString *)identifier {
    NSMutableDictionary *searchDictionary = [[NSMutableDictionary alloc] init];

    [searchDictionary setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];

    NSData *encodedIdentifier = [identifier dataUsingEncoding:NSUTF8StringEncoding];
    [searchDictionary setObject:encodedIdentifier forKey:(__bridge id)kSecAttrGeneric];
    [searchDictionary setObject:encodedIdentifier forKey:(__bridge id)kSecAttrAccount];
    [searchDictionary setObject:serviceName forKey:(__bridge id)kSecAttrService];

    return searchDictionary;
}

- (NSData *)searchKeychainCopyMatching:(NSString *)identifier {
    NSMutableDictionary *searchDictionary = [self newSearchDictionary:identifier];

    [searchDictionary setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];
    [searchDictionary setObject:(id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];

    CFDataRef dataRef;
    OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary,
                                      (CFTypeRef *)&dataRef);

    if (status != errSecSuccess) {
#ifdef DEBUG
        NSLog(@"%s - No OSStatus errSecSuccess. Caused by SecItemCopyMatching", __PRETTY_FUNCTION__);
#endif
        return nil;
    }
    NSData *result = (__bridge_transfer NSData *)dataRef;
    return result;
}

当应用程序启动- (NSData *)searchKeychainCopyMatching:(NSString *)标识符时,函数将从密钥链加载值。一段时间内一切正常。但是在大约15个成功的值请求之后,我得到了一个错误。

OSStatus代码-34018

SecItemCopyMatching函数返回该错误代码。文件上说

@result --结果代码。参见“安全错误代码”(SecBase.h).

但是在SecBase.h中只指定了这些OSStatus代码。

代码语言:javascript
复制
enum
{
    errSecSuccess                               = 0,       /* No error. */
    errSecUnimplemented                         = -4,      /* Function or operation not implemented. */
    errSecIO                                    = -36,     /*I/O error (bummers)*/
    errSecOpWr                                  = -49,     /*file already open with with write permission*/
    errSecParam                                 = -50,     /* One or more parameters passed to a function where not valid. */
    errSecAllocate                              = -108,    /* Failed to allocate memory. */
    errSecUserCanceled                          = -128,    /* User canceled the operation. */
    errSecBadReq                                = -909,    /* Bad parameter or invalid state for operation. */
    errSecInternalComponent                     = -2070,
    errSecNotAvailable                          = -25291,  /* No keychain is available. You may need to restart your computer. */
    errSecDuplicateItem                         = -25299,  /* The specified item already exists in the keychain. */
    errSecItemNotFound                          = -25300,  /* The specified item could not be found in the keychain. */
    errSecInteractionNotAllowed                 = -25308,  /* User interaction is not allowed. */
    errSecDecode                                = -26275,  /* Unable to decode the provided data. */
    errSecAuthFailed                            = -25293,  /* The user name or passphrase you entered is not correct. */
};

这些值不会被重写,已经检查过了。

最后但并非最不重要的是搜索字典:

编辑-新信息

我调试了一整天,发现了一些消息。我正在下载一个包含可执行包的Zip文件。这是一个内部应用程序,所以不要担心2.7和2.8点的审查指南。成功加载包后,将出现“应享权利”错误。

代码语言:javascript
复制
NSBundle *bundle = nil;
NSError *error = nil;
bundle = [[NSBundle alloc] initWithPath:bundlePath];
if (!bundle) {
    return nil;
}

// Here i can access the keychain as usually
[bundle loadAndReturnError:&error];
// Well here it suddenly doesn't work anymore
// error is also nil

好的,内部的包代码不使用密钥链。也许这是某种安全逻辑?有什么线索吗?

EN

回答 1

Stack Overflow用户

发布于 2013-12-28 17:11:54

此错误表示应用程序的应享权利存在问题。Found this:原因通常是应用程序权限中的应用程序标识符前缀与供应配置文件中的应用程序标识符前缀不匹配。

若要验证,请使用codesign工具查看应用程序的应享权利:

代码语言:javascript
复制
codesign -d --entitlements - MyApp.app/

然后,将App标识符前缀与供应配置文件中的前缀进行比较:

代码语言:javascript
复制
cat MyApp.app/embedded.mobileprovision
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20816995

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档