蓝牙警告 Xcode?
我正在尝试通过制作一个简单的点对点蓝牙聊天应用程序来了解如何使用蓝牙连接。我遇到了一些问题,因为我是探索 GameKit 和蓝牙的新手,希望有人可以帮助我。我认为这是一个格式问题,但我可能是错的。基本上,当在两个设备之间发送消息时,我想在显示消息的 UIAlertView 弹出窗口中使用消息来源的设备名称。例如,“Johnny 的 Iphone 说:...”
这是我处理 AlertVIew 的代码:
- (void) receiveData:(NSData *)data
fromPeer:(NSString *)peer
inSession:(GKSession *)session
context:(void *)context {
//---convert the NSData to NSString---
NSString* str;
str = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:(@"Chat Message: %@", peer)
message:str
delegate:self
cancelButtonTitle:@"REPLY"
otherButtonTitles:nil];
[alert show];
[alert release];
}
在上面,我尝试使用“peer”来设置名称,但它不起作用。我尝试将对等点初始化为字符串,然后传递它,但这也不起作用。在这两种情况下,我都会收到一串 9 或 10 个数字,并且发送的任何消息都会显示在下面。我哪里出错了,我应该做什么?
I'm trying to learn about using bluetooth connectivity through making a simple peer to peer bluetooth chat app. I'm hitting a bit of a problem as I'm new to exploring GameKit and Bluetooth and am hoping someone can help me. I think it's a formatting issue, but I could be very wrong. Basically when sending messages between both devices I'd like to use the name of the device that the message is coming from in the UIAlertView popup that displays the message. For example, 'Johnny's Iphone says:...'
Here's the bit of my code dealing with the AlertVIew:
- (void) receiveData:(NSData *)data
fromPeer:(NSString *)peer
inSession:(GKSession *)session
context:(void *)context {
//---convert the NSData to NSString---
NSString* str;
str = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:(@"Chat Message: %@", peer)
message:str
delegate:self
cancelButtonTitle:@"REPLY"
otherButtonTitles:nil];
[alert show];
[alert release];
}
In the above I'm trying to use 'peer' to set the name but it's not working. I've tried initialising peer as a string and then passing it but this isn't working either. In both cases I get a string of 9 or 10 numbers with whatever message was sent displayed below. Where am I going wrong and what should I be doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
[session displayNameForPeer:peer]
这将返回“显示名称”Use
[session displayNameForPeer:peer]
which will return you the "display name"