无法识别iOS OSStatus代码 [英] Unable to identify iOS OSStatus Code

查看:228
本文介绍了无法识别iOS OSStatus代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS应用程序中有一个非常奇怪的行为。
我从iOS 6切换到iOS 7.在iOS 6中,一切都运行良好。

I have a really strange behavior in an iOS App. I switched from iOS 6 to iOS 7. In iOS 6 everything worked perfectly.

- (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次成功的价值请求后,我收到错误。

When the App starts the - (NSData *)searchKeychainCopyMatching:(NSString *)identifier function loads the values from the keychain. Everything works fine for a while. But after about 15 successful value requests I get an error.

OSStatus Code -34018

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

The SecItemCopyMatching function returns that error code. The documentation says

@result结果代码。请参阅安全错误代码(SecBase.h)。

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

But looking in the SecBase.h there are only these OSStatus codes specified.

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. */
};

这些值不会被覆盖,已经检查过。

The values doesn't get overridden, already checked.

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

And last but not least the search dictionary:

修改 - 新信息

我整天都在调试,我发现了一些消息。我正在下载包含可执行Bundle的Zip文件。这是一个内部应用程序,因此不必担心审查指南中的第2.7和2.8点。成功加载捆绑包后,将显示权利错误。

I was debugging the whole day and I found some news. I'm downloading a Zip-File containing an executable Bundle. This is a In-House App so no worries about point 2.7 and 2.8 in the review guidelines. After successfully loading the bundle the entitlements error appears.

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

内部的捆绑代码不使用密钥链。可能这是某种安全逻辑?任何线索?

Well the bundle code inside does not use the keychain. May be this is some kind of security logic? Any clues?

推荐答案

此错误表示您的应用的权利存在问题。找到这个:原因往往是应用程序权利中的应用程序标识符前缀与配置文件中的应用程序标识符前缀不匹配。

This error indicates a problem with your app's entitlements. Found this: The cause is often that the App Identifier Prefix in the app's entitlements doesn't match the App Identifier Prefix in the provisioning profile.

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

To verify, use the codesign tool to view your app's entitlements:

codesign -d --entitlements - MyApp.app/

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

Then, compare the App Identifier Prefix to that in the provisioning profile:

cat MyApp.app/embedded.mobileprovision

这篇关于无法识别iOS OSStatus代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆