Multipeer Connectivity stops working when user turns off and on bluetooth
I am using multipeer connectivity in ios7 in my app. The file sending and
receiving works absolutely fine, but in the moment that a user accesses
from within my app the control center (or even settings) and switches off
either bluetooth or wifi, the file exchange stops working. When the user
witches both of them back on, still it doesn't work. In order for them to
work again, the user must close and re-open the app.
The files are sent in this way:
MCSession *session = [[MCSession alloc]
initWithPeer:key];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [[NSDateComponents
alloc] init];
dateComponents.year = 2100;
dateComponents.month = 1;
dateComponents.day = 1;
dateComponents.hour = 0;
dateComponents.minute = 0;
dateComponents.second = 0;
NSDate *referenceDate = [gregorian dateFromComponents:
dateComponents];
NSDate *now = [NSDate date];
NSTimeInterval interval = [now
timeIntervalSinceDate:referenceDate];
NSData *Recording = [NSData
dataWithContentsOfFile:myFilePath];
NSString* str = [NSString stringWithFormat:@"%@.ext",
button.titleLabel.text];
NSMutableDictionary *dict = [[NSMutableDictionary
alloc] init];
[dict setObject:str forKey:@"fileName"];
[dict setObject:@"Recording" forKey:@"fileType"];
[dict setObject:Recording forKey:@"FileData"];
NSData *myData = [NSKeyedArchiver
archivedDataWithRootObject:dict];
[browser invitePeer:key
toSession:session
withContext:myData
timeout:interval];
The user can reload the devices at any time using:
[browser startBrowsingForPeers];
I think that the problem is the timeout, but I am not sure.
No comments:
Post a Comment