蓝牙警告 Xcode?

发布于 2024-11-17 20:15:57 字数 1015 浏览 2 评论 0原文

我正在尝试通过制作一个简单的点对点蓝牙聊天应用程序来了解如何使用蓝牙连接。我遇到了一些问题,因为我是探索 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人的歌 2024-11-24 20:15:57

使用 [session displayNameForPeer:peer] 这将返回“显示名称”

Use [session displayNameForPeer:peer] which will return you the "display name"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文