【问题标题】:Send data over Bluetooth using GameKit crash使用 GameKit 崩溃通过蓝牙发送数据
【发布时间】:2010-11-05 03:25:00
【问题描述】:

我正在尝试使用以下方法通过 GameKit 蓝牙发送简单数据。但是,当我的 2 台设备成功连接并点击发送按钮时,它只会在显示“EXC_BAD_ACCESS”的最后一行崩溃。知道有什么问题吗?

- (IBAction)sendAction:(id)sender {
    // convert an NSString to NSData
    NSString *str = @"Yahooooo!!";
    NSData *data = [str dataUsingEncoding: NSASCIIStringEncoding];
    [currentSession sendDataToAllPeers:data withDataMode:GKSendDataReliable error:nil];
}

【问题讨论】:

    标签: ios bluetooth gamekit


    【解决方案1】:

    您可能没有正确管理 currentSession 变量的保留计数。假设 currentSession 是一个成员变量,当你分配给 currentSession 时,如果它没有被称为 alloc 或 copy 的方法返回,你需要保留它直到你完成它,此时你应该释放它。

    您应该查看内存管理编程指南:

    http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-21
      • 2014-11-16
      • 1970-01-01
      • 1970-01-01
      • 2021-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多