Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use iPhone as a game controller in a tvOS app?

Tags:

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/

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?

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

like image 892
AaronBaker Avatar asked Sep 11 '15 01:09

AaronBaker


People also ask

Can I use my iPhone as a game controller?

Today, companies like Joypad Inc. are turning our iPhones into game controllers. Joypad's eponymous free app syncs directly with iPad, Mac, and PC games over bluetooth or WiFi to let gamers use their smartphone as a controller to play their favorite games on various NES-style control pads.

Can Apple TV Remote work as game controller?

For most Apple TV owners, the first way you play games is by using the Siri remote to control them. All you need to do is launch a game and then flip the remote sideways and—thanks to the accelerometer and gyroscope in it being able to understand how you're holding it—you'll be ready to play games.

How do I use my iPhone as a controller for Apple TV?

I understand you want to use your iPhone as a controller for the Apple TV. I'll be happy to explain. You can use the Apple TV Remote app for iPhone: Set up the Apple TV Remote on your iPhone, iPad, or iPod touch You can also use any of these accessories as controllers for Apple Arcade: Connect a wireless game controller to your Apple device

How to use a virtual gamepad on an iPhone?

Once the devices are connected, launch the game. You might need to change the gamepad display in the iPhone app to match the buttons to your configuration. Tap on the small joystick icon on the app and select the desired style. You can now play the games using the virtual gamepad on your iPhone.

Can a smartphone be used as a wireless controller for gaming?

The idea of using smartphone as a wireless controller for playing games on the computer is kinda cool, and we have already seen two Android apps that get the job done. I recently got an iPhone and wanted to try out the same on it.

Can you play games on Apple TV with the Siri Remote?

While the fourth-generation Apple TV supports a variety of MFi Game Controllers, most games can also still technically be played using the Siri Remote as well.


3 Answers

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 (Receiver)

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

libRemoteReceiver.a

RemoteReceiver.h

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

#import "RemoteReceiver.h"

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

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

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

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

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

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

iOS Project (Sender/Remote Control)

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

libRemoteSender.a

RemoteSender.h

Step 2: Import the RemoteSender class in your ViewController

#import "RemoteSender.h"

Step 3: Update ViewController.m with the following code

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

Step 4: Allocate and initialize the remoteSender object

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

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];
}
like image 124
vivianaranha Avatar answered Sep 21 '22 15:09

vivianaranha


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:

https://github.com/robreuss/VirtualGameController

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

All features:

  • Mimics API for Apple's GameController framework (GCController)
  • Device motion support in software controllers
  • Custom controller elements
  • Custom element mapping
  • WiFi-based, with Bluetooth fallback
  • Controller-forwarding
  • Works with Apple TV Simulator
  • Unlimited number of hardware controllers on Apple TV (using controller forwarding)
  • 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)
  • Easy-to-implement 3d touch on software controllers
  • Leverage on-screen and Bluetooth keyboards using software controllers (including with Apple TV)
  • Support for snapshots (compatible with Apple's snapshot format)
  • Swift 2.1
  • Framework-based
like image 20
Rob Reuss Avatar answered Sep 20 '22 15:09

Rob Reuss


It looks like CFNetwork is available on TvOS. Try this question for help on using 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.

like image 23
WolfLink Avatar answered Sep 17 '22 15:09

WolfLink