在tvOS应用程序中使用iPhone作为游戏控制器?

时间:2021-05-24 03:41:44

During the Apple TV announcement, the developers of Crossy Road demonstrated using an iPhone as a 2nd controller for an Apple tv game:

在Apple TV宣布期间,Crossy Road的开发人员使用iPhone作为Apple电视游戏的第二控制器:

http://www.macrumors.com/2015/09/09/cooperative-play-for-crossy-road/

http://www.macrumors.com/2015/09/09/cooperative-play-for-crossy-road/

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?

我的第一个想法是使用Multipeer Connectivity Framework实现这一点。但是,tvOS不支持它。有没有一种很好的方法可以在没有Multipeer Connectivity的情况下将iPhone连接到Apple TV?

Update: It doesn't appear that I can use GameKit because GKPeerPickerController has been removed from GameKit on tvOS.

更新:我似乎无法使用GameKit,因为GKPeerPickerController已从tvOS上的GameKit中删除。

4 个解决方案

#1


10  

You can try my library. I built this for my apps maybe helpful for you too.

你可以试试我的图书馆。我为我的应用程序构建这个也可能对你有帮助。

https://github.com/vivianaranha/TvOS_Remote

https://github.com/vivianaranha/TvOS_Remote

Apple TV Project (Receiver)

Apple TV Project(接收器)

Step 1: Create a TvOS Project and import the files from RemoteReceiver

步骤1:创建TvOS项目并从RemoteReceiver导入文件

libRemoteReceiver.a

libRemoteReceiver.a

RemoteReceiver.h

RemoteReceiver.h

Step 2: In your ViewController.m file import the RemoteReceiver.h file

步骤2:在ViewController.m文件中导入RemoteReceiver.h文件

#import "RemoteReceiver.h"

Step 3: Inside ViewController.m file add the following code

第3步:在ViewController.m文件中添加以下代码

@interface ViewController () <RemoteReceiverDelegate>
@property (nonatomic, strong) RemoteReceiver *remoteReceiver;
@end

Step 4: Inside viewDidLoad alloc and set the delegate for remoteReceiver

第4步:在viewDidLoad内部为remoteReceiver分配和设置委托

self.remoteReceiver = [[RemoteReceiver alloc] init];
self.remoteReceiver.delegate = self;

Step 5: Implement the following delegate method for messages send from iOS remote app

步骤5:为从iOS远程应用程序发送的消息实现以下委托方法

-(void) didReceiveMessage:(NSDictionary *)userInfo{
    NSLog(@"%@",userInfo);
}

iOS Project (Sender/Remote Control)

iOS项目(发件人/远程控制)

Step 1: Create an iOS Project and import the files from RemoteSender

步骤1:创建iOS项目并从RemoteSender导入文件

libRemoteSender.a

libRemoteSender.a

RemoteSender.h

RemoteSender.h

Step 2: Import the RemoteSender class in your ViewController

第2步:在ViewController中导入RemoteSender类

#import "RemoteSender.h"

Step 3: Update ViewController.m with the following code

第3步:使用以下代码更新ViewController.m

@interface ViewController ()
@property(nonatomic, strong) RemoteSender *remoteSender;
@end

Step 4: Allocate and initialize the remoteSender object

第4步:分配并初始化remoteSender对象

self.remoteSender = [[RemoteSender alloc] init];

Step 5: Implement gestures and methods (Check below for just button code)

第5步:实现手势和方法(检查下面的按钮代码)

- (IBAction)sendSomeInformation:(id)sender {
    NSDictionary *theDictionaryToSendToTV = @{@"name": @"John Smith",@"age": @"35", @"address":@"123 Main St"};
    [self.remoteSender sendInfo:theDictionaryToSendToTV];
}

#2


6  

I've developed a framework that supports the creation of software-based controllers and directs the input through a MFi profile, allowing you to have a single codebase that handles both software and hardware controllers. Many other features as well:

我开发了一个框架,支持创建基于软件的控制器,并通过MFi配置文件引导输入,允许您拥有一个处理软件和硬件控制器的单一代码库。许多其他功能:

https://github.com/robreuss/VirtualGameController

https://github.com/robreuss/VirtualGameController

NSNetservice is used for connectivity, and all Apple platforms are supported (iOS, OS X, watchOS and tvOS).

NSNetservice用于连接,支持所有Apple平台(iOS,OS X,watchOS和tvOS)。

All features:

所有功能:

  • Mimics API for Apple's GameController framework (GCController)
  • Apple的GameController框架(GCController)的Mimics API
  • Device motion support in software controllers
  • 软件控制器中的设备运动支持
  • Custom controller elements
  • 定制控制器元素
  • Custom element mapping
  • 自定义元素映射
  • WiFi-based, with Bluetooth fallback
  • 基于WiFi,具有蓝牙备用功能
  • Controller-forwarding
  • 控制器转发
  • Works with Apple TV Simulator
  • 适用于Apple TV Simulator
  • Unlimited number of hardware controllers on Apple TV (using controller forwarding)
  • Apple TV上无限数量的硬件控制器(使用控制器转发)
  • Ability to enhance inexpensive slide-on/form-fitting controllers with motion, extended profile elements and custom elements
  • 能够增强廉价的滑动/形状配合控制器,包括运动,扩展轮廓元素和自定义元素
  • iCade controller support (mapped through the MFi profiles so they appear as MFi hardware)
  • iCade控制器支持(通过MFi配置文件映射,因此它们显示为MFi硬件)
  • Easy-to-implement 3d touch on software controllers
  • 易于在软件控制器上实现3D触摸
  • Leverage on-screen and Bluetooth keyboards using software controllers (including with Apple TV)
  • 利用软件控制器(包括Apple TV)利用屏幕和蓝牙键盘
  • Support for snapshots (compatible with Apple's snapshot format)
  • 支持快照(与Apple的快照格式兼容)
  • Swift 2.1
  • Swift 2.1
  • Framework-based
  • 基于框架

#3


3  

It looks like CFNetwork is available on TvOS. Try this question for help on using CFNetwork.

看起来CFNetwork可以在TvOS上使用。试试这个问题以获得有关使用CFNetwork的帮助。

EDIT: also take a look at CoreBluetooth. I'm working on the same issue - I want to have a companion iPhone app for my TvOS app.

编辑:还看看CoreBluetooth。我正在研究同样的问题 - 我想为我的TvOS应用程序配备一个配套的iPhone应用程序。

#4


0  

Well, I'm not sure it qualifies as a "good way", but GKMatchRequest and GKMatchmaker are in there, so maybe that's what they're using.

好吧,我不确定它是否属于“好方法”,但是GKMatchRequest和GKMatchmaker都在那里,所以也许这就是他们正在使用的东西。

https://developer.apple.com/library/prerelease/tvos/documentation/GameKit/Reference/GKMatchRequest_Ref/

https://developer.apple.com/library/prerelease/tvos/documentation/GameKit/Reference/GKMatchRequest_Ref/

#1


10  

You can try my library. I built this for my apps maybe helpful for you too.

你可以试试我的图书馆。我为我的应用程序构建这个也可能对你有帮助。

https://github.com/vivianaranha/TvOS_Remote

https://github.com/vivianaranha/TvOS_Remote

Apple TV Project (Receiver)

Apple TV Project(接收器)

Step 1: Create a TvOS Project and import the files from RemoteReceiver

步骤1:创建TvOS项目并从RemoteReceiver导入文件

libRemoteReceiver.a

libRemoteReceiver.a

RemoteReceiver.h

RemoteReceiver.h

Step 2: In your ViewController.m file import the RemoteReceiver.h file

步骤2:在ViewController.m文件中导入RemoteReceiver.h文件

#import "RemoteReceiver.h"

Step 3: Inside ViewController.m file add the following code

第3步:在ViewController.m文件中添加以下代码

@interface ViewController () <RemoteReceiverDelegate>
@property (nonatomic, strong) RemoteReceiver *remoteReceiver;
@end

Step 4: Inside viewDidLoad alloc and set the delegate for remoteReceiver

第4步:在viewDidLoad内部为remoteReceiver分配和设置委托

self.remoteReceiver = [[RemoteReceiver alloc] init];
self.remoteReceiver.delegate = self;

Step 5: Implement the following delegate method for messages send from iOS remote app

步骤5:为从iOS远程应用程序发送的消息实现以下委托方法

-(void) didReceiveMessage:(NSDictionary *)userInfo{
    NSLog(@"%@",userInfo);
}

iOS Project (Sender/Remote Control)

iOS项目(发件人/远程控制)

Step 1: Create an iOS Project and import the files from RemoteSender

步骤1:创建iOS项目并从RemoteSender导入文件

libRemoteSender.a

libRemoteSender.a

RemoteSender.h

RemoteSender.h

Step 2: Import the RemoteSender class in your ViewController

第2步:在ViewController中导入RemoteSender类

#import "RemoteSender.h"

Step 3: Update ViewController.m with the following code

第3步:使用以下代码更新ViewController.m

@interface ViewController ()
@property(nonatomic, strong) RemoteSender *remoteSender;
@end

Step 4: Allocate and initialize the remoteSender object

第4步:分配并初始化remoteSender对象

self.remoteSender = [[RemoteSender alloc] init];

Step 5: Implement gestures and methods (Check below for just button code)

第5步:实现手势和方法(检查下面的按钮代码)

- (IBAction)sendSomeInformation:(id)sender {
    NSDictionary *theDictionaryToSendToTV = @{@"name": @"John Smith",@"age": @"35", @"address":@"123 Main St"};
    [self.remoteSender sendInfo:theDictionaryToSendToTV];
}

#2


6  

I've developed a framework that supports the creation of software-based controllers and directs the input through a MFi profile, allowing you to have a single codebase that handles both software and hardware controllers. Many other features as well:

我开发了一个框架,支持创建基于软件的控制器,并通过MFi配置文件引导输入,允许您拥有一个处理软件和硬件控制器的单一代码库。许多其他功能:

https://github.com/robreuss/VirtualGameController

https://github.com/robreuss/VirtualGameController

NSNetservice is used for connectivity, and all Apple platforms are supported (iOS, OS X, watchOS and tvOS).

NSNetservice用于连接,支持所有Apple平台(iOS,OS X,watchOS和tvOS)。

All features:

所有功能:

  • Mimics API for Apple's GameController framework (GCController)
  • Apple的GameController框架(GCController)的Mimics API
  • Device motion support in software controllers
  • 软件控制器中的设备运动支持
  • Custom controller elements
  • 定制控制器元素
  • Custom element mapping
  • 自定义元素映射
  • WiFi-based, with Bluetooth fallback
  • 基于WiFi,具有蓝牙备用功能
  • Controller-forwarding
  • 控制器转发
  • Works with Apple TV Simulator
  • 适用于Apple TV Simulator
  • Unlimited number of hardware controllers on Apple TV (using controller forwarding)
  • Apple TV上无限数量的硬件控制器(使用控制器转发)
  • Ability to enhance inexpensive slide-on/form-fitting controllers with motion, extended profile elements and custom elements
  • 能够增强廉价的滑动/形状配合控制器,包括运动,扩展轮廓元素和自定义元素
  • iCade controller support (mapped through the MFi profiles so they appear as MFi hardware)
  • iCade控制器支持(通过MFi配置文件映射,因此它们显示为MFi硬件)
  • Easy-to-implement 3d touch on software controllers
  • 易于在软件控制器上实现3D触摸
  • Leverage on-screen and Bluetooth keyboards using software controllers (including with Apple TV)
  • 利用软件控制器(包括Apple TV)利用屏幕和蓝牙键盘
  • Support for snapshots (compatible with Apple's snapshot format)
  • 支持快照(与Apple的快照格式兼容)
  • Swift 2.1
  • Swift 2.1
  • Framework-based
  • 基于框架

#3


3  

It looks like CFNetwork is available on TvOS. Try this question for help on using CFNetwork.

看起来CFNetwork可以在TvOS上使用。试试这个问题以获得有关使用CFNetwork的帮助。

EDIT: also take a look at CoreBluetooth. I'm working on the same issue - I want to have a companion iPhone app for my TvOS app.

编辑:还看看CoreBluetooth。我正在研究同样的问题 - 我想为我的TvOS应用程序配备一个配套的iPhone应用程序。

#4


0  

Well, I'm not sure it qualifies as a "good way", but GKMatchRequest and GKMatchmaker are in there, so maybe that's what they're using.

好吧,我不确定它是否属于“好方法”,但是GKMatchRequest和GKMatchmaker都在那里,所以也许这就是他们正在使用的东西。

https://developer.apple.com/library/prerelease/tvos/documentation/GameKit/Reference/GKMatchRequest_Ref/

https://developer.apple.com/library/prerelease/tvos/documentation/GameKit/Reference/GKMatchRequest_Ref/