I am developing a chat application using bluetooth.Initially i was sending text only and was receiving it correctly.
NSData *mydata=[str dataUsingEncoding:NSUTF8StringEncoding]; [self sendPacket:mydata ofType:0];
-(void) sendPacket:(NSData*)data ofType:(PacketType)type {
NSMutableData * newPacket = [NSMutableData dataWithCapacity:([data length]+sizeof(uint32_t))];
uint32_t swappedType = CFSwapInt32HostToBig((uint32_t)type);
[newPacket appendBytes:&swappedType length:sizeof(uint32_t)];
[newPacket appendData:data];
NSError *error;
[mSession sendDataToAllPeers:newPacket withDataMode:GKSendDataReliable error:&error];
}
at receiver end i had following method which was called whenever i send any text(data).
self.mSession.delegate = self; [self.mSession setDataReceiveHandler:self withContext:nil];
PacketType header;
uint32_t swappedHeader;
if ([data length] >= sizeof(uint32_t)) {
[data getBytes:&swappedHeader length:sizeof(uint32_t)];
header = (PacketType)CFSwapInt32BigToHost(swappedHeader);
}
UIImage *scroll = [UIImage imageNamed:@"textViewbor"];
UIImageView *scrollImage = [[UIImageView alloc] initWithImage:scroll];
scrollImage.frame=CGRectMake(1, 30,318, 160);
[self.view addSubview:scrollImage];
UIScrollView *send = [[UIScrollView alloc]initWithFrame:CGRectMake(2,35, 316,140)];
send.contentSize = CGSizeMake(send.frame.size.width, [currentY intValue]+[height intValue]+150);
CGPoint offSet= CGPointMake(10, [currentY intValue]-[[heightArray lastObject]intValue]-100);
[send setContentOffset:offSet animated:NO];
if((header==PacketTypeText))
{ //data is text type }
else { //data is image type }
Now my problem is that receive data is called whenever i send text but it is not called when i send imageData. to send image i have used following
(void)imagePickerController:(UIImagePickerController *)pick didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{ self.img=image;
NSData *imgData=UIImagePNGRepresentation(image); [self sendPacket:imgData ofType:1];
}
Can anybody tell me why is it so?It will be a great help.