Hi list. I'm trying to connect to a phone device until it is reachable. I followed good advices from the list telling me to not retry too quickly to avoid airport and other wireless devices problems. So here is my problem, code follows. With this code, it works almost perfectly, but sometimes, after a long period of "retrying" (device has gone for hours or less, and is back), it seem it is impossible to get connected again, According to last line of log ("Connecting...") it seem the connection result is never called. I made some tests arounf this withPageTimeout: parameters without knowing exactly what it does, but this value gave me reasonable connectionn timeout, but If someone can tell me what the "page" mean ! And last, if someone has a good experience of this kind of algorithm, or can tell me the best way to continuously try to get a device, I would be happy to know ! Best regards, -(void)_connect { if (DEBUG) NSLog(@"Connection request"); if ([ self isConnected ]) { if (DEBUG) NSLog(@"Already connected"); return; } if(! [[self class] bluetoothAvailable]) // No bluetooth hardware detected { if (DEBUG) NSLog(@"No bluetooth Hardware detected"); return; } if (! device) // No device supplied { if (DEBUG) NSLog(@"No Device supplied"); return; } if (DEBUG) NSLog(@"Connecting..."); [self _setState: kBTConnectingState]; [ device openConnection: self withPageTimeout:10000 authenticationRequired: NO]; } -(void)connectionComplete:(IOBluetoothDevice*)aDevice status:(IOReturn)status { if (DEBUG) NSLog(@"Connection result (device)"); IOBluetoothSDPServiceRecord *dialupServiceRecord; BluetoothRFCOMMChannelID rfcommChannelID; if (status != kIOReturnSuccess) { [ self _retryConnect ]; return; } [...] } -(void)_retryConnect { if (DEBUG) NSLog(@"Retrying connection in 30s"); [ self _setState: kBTConnectingState]; [...] [retryTimer release]; retryTimer = [[ NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(connect:) userInfo:nil repeats:NO ]retain]; } -(void)connect:(NSTimer*)timer { if (DEBUG) NSLog(@"Retrying"); [ self _connect ]; } -- Yann Bizeul - yann at tynsoe.org http://projects.tynsoe.org/ -- Yann Bizeul - yann at tynsoe.org http://projects.tynsoe.org/ _______________________________________________ bluetooth-dev mailing list | bluetooth-dev@lists.apple.com Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/bluetooth-dev Do not post admin requests to the list. They will be ignored.
participants (1)
-
Yann Bizeul