0

我正在开发一个支持 iBeacon 的 iOS 应用程序,当应用程序进入受监控的 iBeacon 所在的区域时,它需要在应用程序从终止状态进入后台时发送 HTTP 请求。除了无法读取某些凭据信息外,一切正常保存在钥匙串中。我不确定这是否与 Keychain 或 iBeacon 或两者有关。但这就是我的代码的样子,

当我保存我的凭据时(我使用应用程序钥匙串包装代码),

KeychainItemWrapper* keyChain = [[KeychainItemWrapper alloc] initWithIdentifier:keyChainIdentifier accessGroup:nil];
[keyChain setObject:@"MY_APP_CREDENTIALS" forKey:(__bridge id)kSecAttrService];
                [keyChain setObject:myUserName forKey:(__bridge id)kSecAttrAccount];
                [keyChain setObject:myPassword forKey:(__bridge id)kSecValueData];
                [keyChain setObject:(__bridge id)kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly forKey:(__bridge id)kSecAttrAccessible];

现在,iBeacon 部分,

- (void)locationManager:(CLLocationManager *)manager
  didDetermineState:(CLRegionState)state
          forRegion:(CLBeaconRegion *)region
{

if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive)
{
    // don't send any notifications
    return;
}

if (state == CLRegionStateInside)
{
    NSLog(@"Inside beacon region");

    KeychainItemWrapper* keyChain = [[KeychainItemWrapper alloc] initWithIdentifier:keyChainIdentifier accessGroup:nil];

    NSString *username =[keyChain objectForKey:(__bridge id)kSecAttrAccount];
    NSString *password =[keyChain objectForKey:(__bridge id)kSecValueData];

    [self.locationManager startRangingBeaconsInRegion:region];

    if (username.length > 0 && password.length > 0 ) {
        [self sendRequest:userName passCode:password];
    }else {
        // This is where it ends up when the app is TERMINATED and entering to the region !!!
        [self displayError];
        NSLog(@"I CAN SEE THIS !!!");
    }

}
 }

我杀死应用程序,锁定屏幕,然后按住设备进入iBeacon区域,然后我可以看到一切按照逻辑发生但只能看到错误消息。任何帮助将非常感激。

4

0 回答 0