IOS Gamekit GKValidArgumentException错误

IOS Gamekit GKValidArgumentException错误,ios,bluetooth,gamekit,connectivity,Ios,Bluetooth,Gamekit,Connectivity,您好,我正在使用gamekit连接两个IOS设备,以便在它们之间传输数据,下面是iam在此使用的代码 .h @property (nonatomic,strong)GKSession *sessionObj; ... .m ... GKPeerPickerController *connectionPicker = [[GKPeerPickerController alloc] init]; connectionPicker.delegate = self; //NOTE - GKPe

您好,我正在使用gamekit连接两个IOS设备,以便在它们之间传输数据,下面是iam在此使用的代码

.h 

@property (nonatomic,strong)GKSession *sessionObj;
...

.m

...
GKPeerPickerController *connectionPicker = [[GKPeerPickerController alloc] init];
connectionPicker.delegate = self;

//NOTE - GKPeerPickerConnectionTypeNearby is for Bluetooth connection, you can do the same thing over Wi-Fi with different type of connection
connectionPicker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
[connectionPicker show];

sessionObj = [[GKSession alloc] initWithSessionID:@"com.myapp.connect" displayName:nil sessionMode:GKSessionModePeer];
sessionObj.delegate = self;
因此,当我运行应用程序时,它会转到GKPeerPickerControllerDelegate

-(GKSession *)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type{
 return sessionObj;
} 一旦它从委托方法返回,就会抛出一个错误

*** Terminating app due to uncaught exception 'GKInvalidArgumentException', reason: 'A vaild GKSession object with a GKSessionModePeer mode must be supplied, or to create a default GKSession object return 'nil' in the implementation of -peerPickerController:sessionForConnectionType:. Supplied object was: (null description) with session mode: 0'
*** First throw call stack:
(0x1335052 0x1155d0a 0x12dda78 0x12dd9e9 0x665e0 0x65798 0x64e9a 0x64e13 0x5d15cb 0x64cf7 0x63237 0xb781 0xb438 0x5099d6 0x50a8a6 0x519743 0x51a1f8 0x50daa9 0x1d67fa9 0x13091c5 0x126e022 0x126c90a 0x126bdb4 0x126bccb 0x50a2a7 0x50ba9b 0xc12d 0x75f5 0x1)
terminate called throwing an exception(lldb) 

您能告诉我这里出了什么问题吗。

您在哪里设置GKSession或GKSessionLegate?您正在寻找一行代码,如myGKSessionVariable=[[GKSession alloc]initWithSessionID:sessionID displayName:nil sessionMode:GKSessionModePeer];是的,我已经创建了一个,并在connectionPicker.connectionTypesMask=GKPeerpickerConnectionTypeNearnear下面添加了一个;[connectionPicker show];和在委托中-GKSession*peerPickerController:GKPeerPickerController*picker sessionForConnectionType:GKPeerPickerConnectionTypetype;我正在返回samei,我刚刚用更新的代码编辑了问题。我能够理解它,因为我在模拟器上运行应用程序,所以它会被终止。当我在真实设备上运行相同的程序时,它工作正常。