0

I am working on an iBeacon supported iOS app which requires to send out a HTTP request when the app comes to background from terminates state when it enters a region where a monitored iBeacon is situated in. All works fine excepts it fails to read some credential information saved in the Keychain. I'm not sure whether this has anything to do with Keychain or iBeacon, or both. But this is how my code looks like,

When I save my credentials(I use apps Keychain Wrapper code),

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];

Now, the iBeacon part,

- (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 !!!");
    }

}
 }

I kill the application, lock the screen and then enter into the iBeacon region while holding the device, then I can see everything is happening according to the logic but only can see the error message. Any help would be really appreciated.

chathuram
  • 616
  • 2
  • 5
  • 23
  • Anyone out there who faced the same issue ? Am I doing something silly here, is it not even possible to gain access to the Keychain while app awake for 30 seconds by iBeacon events ? – chathuram Sep 08 '14 at 15:17
  • Also added a question to the Apple iOS developer forum as well https://devforums.apple.com/message/1038517#1038517 – chathuram Sep 10 '14 at 17:57
  • What happens if you set the access type to "kSecAttrAccessibleAlways". I know this is advised against by Apple, but it may help in determining the root cause of your problem. – JTango18 May 04 '16 at 05:44

0 Answers0