NSMutableString *tosend=[[NSMutableString alloc] init];
            [tosend appendString:[NSString stringWithFormat:@"%c",0]];
            [tosend appendString:[NSString stringWithFormat:@"%c",0]];
            [tosend appendString:[NSString stringWithFormat:@"%c",0]];
            [tosend appendString:[NSString stringWithFormat:@"%c",0]];
            [tosend appendString:[NSString stringWithFormat:@"%c",0]];
            [tosend appendString:[NSString stringWithFormat:@"%c",0]];
            [tosend appendString:[NSString stringWithFormat:@"%c",0]];
            [tosend appendString:[NSString stringWithFormat:@"%c",0]];
            NSData *valData = [tosend dataUsingEncoding:NSUTF8StringEncoding];
           
             [peripheral writeValue:valData forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];这样也不行

解决方案 »

  1.   

    先确定你是要发字符0还是二进制数据0,另外可以先试试随便发个abc之类的看看能不能正确收到
      

  2.   

    1、用的是 NSURLConnection 吗?
    2、0x00000000 存储是就是 0.
    3、peripheral 是什么?一个 Socket 封装?
      

  3.   

    这样可以:
            NSMutableData *data=[[NSMutableData alloc] initWithCapacity:0];
            int8_t byte0 = 0xfe;
            [data appendBytes:&byte0 length:sizeof(byte0)];
            int8_t byte1 = 0x82;
            [data appendBytes:&byte1 length:sizeof(byte1)];
            int8_t byte2 = 0x00;
            [data appendBytes:&byte2 length:sizeof(byte2)];
            int8_t byte3 = 0x00;
            [data appendBytes:&byte3 length:sizeof(byte3)];
            int8_t byte4 = 0x00;
            [data appendBytes:&byte4 length:sizeof(byte4)];
            int8_t byte5 = 0x02;
            [data appendBytes:&byte5 length:sizeof(byte5)];        NSLog(@"%@",data);//<fe820000 0002>        [_peripheral writeValue:data forCharacteristic:_characteristic type:CBCharacteristicWriteWithResponse];