Use iPhone as a game controller in a tvOS app?

放肆的年华 提交于 2019-11-29 21:34:11
vivianaranha

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];
}

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
WolfLink

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!