Use iPhone as a game controller in a tvOS app?

后端 未结 4 1028
说谎
说谎 2020-12-23 21:52

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/

4条回答
  •  醉话见心
    2020-12-23 22:34

    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 () 
    @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];
    }
    

提交回复
热议问题