ios - 无法识别 iOS OSStatus 代码
<p><p>我在 iOS 应用程序中有一个非常奇怪的行为。
我从 iOS 6 切换到 iOS 7。在 iOS 6 中一切正常。</p>
<pre><code>- (NSMutableDictionary *)newSearchDictionary:(NSString *)identifier {
NSMutableDictionary *searchDictionary = [ init];
;
NSData *encodedIdentifier = ;
;
;
;
return searchDictionary;
}
- (NSData *)searchKeychainCopyMatching:(NSString *)identifier {
NSMutableDictionary *searchDictionary = ;
;
;
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;
}
</code></pre>
<p>当应用启动时,<strong>- (NSData *)searchKeychainCopyMatching:(NSString *)identifier</strong> 函数会从钥匙串(keychain)中加载值。一切正常一段时间。但是在大约 15 次成功的值请求之后,我得到了一个错误。</p>
<p><strong>操作系统状态码 -34018</strong></p>
<p>SecItemCopyMatching 函数返回该错误代码。文档说</p>
<p><strong>@result 结果代码。请参阅“安全错误代码”(SecBase.h)。</strong></p>
<p>但在 SecBase.h 中只指定了这些 OSStatus 代码。</p>
<pre><code>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. */
};
</code></pre>
<p>这些值不会被覆盖,已经检查过。</p>
<p>最后但并非最不重要的是搜索字典:</p>
<p> <img src="/image/8NbJH.png" alt="enter image description here"/> </p>
<p><strong>编辑 - 新信息</strong></p>
<p>我调试了一整天,发现了一些消息。我正在下载一个包含可执行包的 Zip 文件。这是一个内部应用程序,因此无需担心审查指南中的第 2.7 点和第 2.8 点。成功加载 bundle 后,出现权利错误。</p>
<pre><code>NSBundle *bundle = nil;
NSError *error = nil;
bundle = [ initWithPath:bundlePath];
if (!bundle) {
return nil;
}
// Here i can access the keychain as usually
;
// Well here it suddenly doesn't work anymore
// error is also nil
</code></pre>
<p>嗯,里面的捆绑代码不使用钥匙串(keychain)。可能这是某种安全逻辑?有什么线索吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>此错误表明您的应用权利存在问题。找到 <a href="https://stackoverflow.com/questions/11088460/keychain-integration-causing-crash-with-missing-entitlement-error-via-comma" rel="noreferrer noopener nofollow">this</a> : 原因通常是应用权利中的应用标识符前缀与配置文件中的应用标识符前缀不匹配。</p>
<p>要进行验证,请使用协同设计工具查看您应用的权利:</p>
<pre><code>codesign -d --entitlements - MyApp.app/
</code></pre>
<p>然后,将 App Identifier Prefix 与配置文件中的进行比较:</p>
<pre><code>cat MyApp.app/embedded.mobileprovision
</code></pre></p>
<p style="font-size: 20px;">关于ios - 无法识别 iOS OSStatus 代码,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/20816995/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/20816995/
</a>
</p>
页:
[1]