BluetoothManager

Discussion in 'iOS Programming' started by DennisBlah, Mar 4, 2014.

  1. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #1
    I got bluetoothmanager working to find my bluetooth devices.
    But I cannot connect my earphone. This should be connected by the PIN code 0000

    I tried setting the pincode before the connect, after the connect. It just wont work.
     
  2. DennisBlah, Mar 13, 2014
    Last edited: Mar 19, 2014

    DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #2
    Does anyone has any experience with pairing devices with BluetoothManager?
    I can turn bluetooth on and off and scan for devices, which will also come up in my list, but I can't figure out how to set the PIN code for pairing the devices..

    There are functions about
    Code:
    In bluetoothDevice:
    - (void)setPIN:(id)fp8;
    
    In Bluetoothmanager:
    - (void)setPincode:(id)fp8 forDevice:(id)fp12;
    
    But setting them before or after connect are no option
    for example:
    Code:
    - (IBAction)connect:(id)sender {
        BTListDevItem *item = (BTListDevItem *)[btDevItems objectAtIndex: 0];
        [logs setText: [NSString stringWithFormat: @"deviceConnect to %@", item.name]];
    
    NSLog(@"Connecting to: %@", item);
    
        [item.btdev setPIN: @"0000"];
        [item.btdev connect];
    }
    
    or
    
    - (IBAction)connect:(id)sender {
        BTListDevItem *item = (BTListDevItem *)[btDevItems objectAtIndex: 0];
        [logs setText: [NSString stringWithFormat: @"deviceConnect to %@", item.name]];
        NSLog(@"Connecting to: %@", item);
    
        [btManager setPincode: @"0000" forDevice: item.btdev];
        [item.btdev connect];
        
    }
    
    Here I'm forcing to connect to the first device in the list, just for testing because I only having bluetooth earphones at the moment. But it wont work.
     
  3. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #3
    I got some error logs about this problem when using this:
    Code:
    - (IBAction)connect:(id)sender {
        BTListDevItem *item = (BTListDevItem *)[btDevItems objectAtIndex: 0];
        NSLog(@"Connecting to: %@", item);
    
        [item.btdev setPIN: @"0000"];
        [item.btdev connect];
    
    //Or this
    //    [btManager setPincode: @"0000" forDevice: item];   
    //    [btManager connectDevice: item];
    }
    
    Logs connecting with bluetoothDevice object:
    Code:
    2014-03-19 13:11:49.791 MediaBundle Test[272:60b] BTM: found device "iPhone Bluetooth Headset" 00:19:E3:AE:1B:94
    
    
    2014-03-19 13:12:07.441 MediaBundle Test[272:60b] Connecting to: 00:19:E3:AE:1B:94
    2014-03-19 13:12:07.443 MediaBundle Test[272:60b] BTM: setting pincode '0000' for device "iPhone Bluetooth Headset" 00:19:E3:AE:1B:94
    2014-03-19 13:12:07.445 MediaBundle Test[272:60b] BTM: connecting to device "iPhone Bluetooth Headset" 00:19:E3:AE:1B:94
    2014-03-19 13:12:07.449 MediaBundle Test[272:60b] CFN Name:UIViewAnimationDidCommitNotification Data:{
        delegate = "<UIViewAnimationBlockDelegate: 0x170226ae0>";
        name = "";
    }
    2014-03-19 13:12:07.704 MediaBundle Test[272:60b] CFN Name:BluetoothDiscoveryStateChangedNotification Data:(null)
    2014-03-19 13:12:07.924 MediaBundle Test[272:60b] CFN Name:UIViewAnimationDidStopNotification Data:{
        delegate = "<UIViewAnimationBlockDelegate: 0x170226ae0>";
        name = "";
    }
    2014-03-19 13:12:09.908 MediaBundle Test[272:60b] BTM: attempting to connect to service 0x00000001 on device "iPhone Bluetooth Headset" 00:19:E3:AE:1B:94
    2014-03-19 13:12:10.175 MediaBundle Test[272:60b] BTM: connection to service 0x00000001 on device "iPhone Bluetooth Headset" 00:19:E3:AE:1B:94 failed with error 151
    2014-03-19 13:12:10.180 MediaBundle Test[272:60b] CFN Name:BluetoothDeviceConnectFailedNotification Data:{
        BluetoothErrorKey = 151;
        BluetoothNotificationNameKey = BluetoothDeviceConnectFailedNotification;
    }
    

    Logs when connecting with the bluetoothManager object:
    It crashes out
    Code:
    2014-03-19 13:14:10.401 MediaBundle Test[279:60b] Connecting to: 00:19:E3:AE:1B:94
    2014-03-19 13:14:10.401 MediaBundle Test[279:60b] BTM: setting pincode '0000' for device 00:19:E3:AE:1B:94
    2014-03-19 13:14:10.402 MediaBundle Test[279:60b] -[BTListDevItem device]: unrecognized selector sent to instance 0x1700588d0
    2014-03-19 13:14:10.403 MediaBundle Test[279:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BTListDevItem device]: unrecognized selector sent to instance 0x1700588d0'
    
    I'm missing an small little thing, I hope someone can help me. Or does anyone know an list about BluetoothManager error codes? like the 151, or 7 (the 7 I received yesterday when I been mingeling the bluetoothmanager and bluetoothdevice objects)
     
  4. Patrakas macrumors newbie

    Joined:
    Jan 25, 2015
    #4
    Hi Dennis, I have the same problem that you had. Did you find a solution?

    Thanks
     
  5. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
  6. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #6
    Hi KarlJay,

    Indeed I also been through these tutorials a while ago ;-)
    But unfortunally, I really need to pair with the device, and whatever I tried... It did not like to pair with my headset or wireless keyboard.

    Hi Patrakas,

    Unfortunally I could not found a solution for this issue.
    I'm not sure if it's even possible to pair 'all' devices with the BluetoothManager.
    Here and there I read that you can only pair certain services with the BluetoothManager... So I did not agree, and found a lot of info which actually told me it should work ;) But ... in the end I gave up, and scrapped this 'part' of my testing application.

    If you do find a solution, please update my post :)
     
  7. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
    #7
    I think there was a post years ago about Apple not allowing BT connection to just any device.

    I don't know BT, so I can't say, but does it give you an error code or is there some standard as to what can and can't be connected to?

    I know Apple has been know for being very strict about what they allow to connect to their sandboxed system. I can imagine that they would have strict rules about BT. Esp now that the new BT standard is supposed to be MUCH faster, it can be used for stealing files (music, movies, etc) and Apple has always tried to stop that.
     

Share This Page