在tvOS应用程序中使用iPhone作为游戏控制器? [英] Use iPhone as a game controller in a tvOS app?
问题描述
在Apple TV公告期间,Crossy Road的开发人员使用iPhone作为Apple电视游戏的第二控制器:
During the Apple TV announcement, the developers of Crossy Road demonstrated using an iPhone as a 2nd controller for an Apple tv game:
http://www.macrumors.com/2015/09/09/cooperative-play -for-crossy-road /
我的第一个想法是使用 Multipeer Connectivity Framework 。但是,tvOS不支持它。有没有一种很好的方法可以将iPhone连接到没有Multipeer Connectivity的Apple TV?
My first thought was to implement this using the Multipeer Connectivity Framework. However, it's not supported on tvOS. Is there a good way to connect an iPhone to an Apple TV without Multipeer Connectivity?
更新:我似乎无法使用GameKit,因为GKPeerPickerController已从tvOS上的GameKit中删除。
Update: It doesn't appear that I can use GameKit because GKPeerPickerController has been removed from GameKit on tvOS.
推荐答案
你可以试试我的库。我为我的应用程序构建这个也可能对你有帮助。
You can try my library. I built this for my apps maybe helpful for you too.
https://github.com/vivianaranha/TvOS_Remote
Apple TV Project(接收方)
Apple TV Project (Receiver)
步骤1:创建TvOS项目并导入文件来自RemoteReceiver
Step 1: Create a TvOS Project and import the files from RemoteReceiver
libRemoteReceiver.a
libRemoteReceiver.a
RemoteReceiver.h
RemoteReceiver.h
步骤2:在ViewController.m文件中导入RemoteReceiver.h文件
Step 2: In your ViewController.m file import the RemoteReceiver.h file
#import "RemoteReceiver.h"
步骤3:在ViewController.m文件中添加以下代码
Step 3: Inside ViewController.m file add the following code
@interface ViewController () <RemoteReceiverDelegate>
@property (nonatomic, strong) RemoteReceiver *remoteReceiver;
@end
步骤4:在viewDidLoad内部分配并设置remoteReceiver的委托
Step 4: Inside viewDidLoad alloc and set the delegate for remoteReceiver
self.remoteReceiver = [[RemoteReceiver alloc] init];
self.remoteReceiver.delegate = self;
步骤5:为从iOS远程应用程序发送的消息实施以下委托方法
Step 5: Implement the following delegate method for messages send from iOS remote app
-(void) didReceiveMessage:(NSDictionary *)userInfo{
NSLog(@"%@",userInfo);
}
iOS项目(发件人/远程控制)
iOS Project (Sender/Remote Control)
步骤1:创建iOS项目并从RemoteSender导入文件
Step 1: Create an iOS Project and import the files from RemoteSender
libRemoteSender.a
libRemoteSender.a
RemoteSender.h
RemoteSender.h
第2步:在ViewController中导入RemoteSender类
Step 2: Import the RemoteSender class in your ViewController
#import "RemoteSender.h"
步骤3:使用更新ViewController.m以下代码
Step 3: Update ViewController.m with the following code
@interface ViewController ()
@property(nonatomic, strong) RemoteSender *remoteSender;
@end
步骤4:分配并初始化remoteSender对象
Step 4: Allocate and initialize the remoteSender object
self.remoteSender = [[RemoteSender alloc] init];
步骤5:实现手势和方法(仅在按钮代码下方检查)
Step 5: Implement gestures and methods (Check below for just button code)
- (IBAction)sendSomeInformation:(id)sender {
NSDictionary *theDictionaryToSendToTV = @{@"name": @"John Smith",@"age": @"35", @"address":@"123 Main St"};
[self.remoteSender sendInfo:theDictionaryToSendToTV];
}
这篇关于在tvOS应用程序中使用iPhone作为游戏控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!