tvOSBrowser icon indicating copy to clipboard operation
tvOSBrowser copied to clipboard

Changes to Availability.h

Open frakman1 opened this issue 9 years ago • 36 comments

Could you please elaborate on how to redefine __TVOS_UNAVAILABLE and __TVOS_PROHIBITED in Availability.h? I've located the Availability.h file but not sure what to change. I tried setting them to 'available' as below but that globally enables everything and caused too many errors.

#define __TVOS_UNAVAILABLE                    __OS_AVAILABILITY(tvos,unavailable)
#define __TVOS_PROHIBITED                     __OS_AVAILABILITY(tvos,unavailable)

frakman1 avatar Oct 14 '15 23:10 frakman1

Well, I got it to work finally but following all the instances of __TV_UNAVAILABLE/PROHIBITED that the compiler complained about and deleting them but that probably wasn't a smart thing to do. Should I have done this instead in Availability.h ?

#ifndef __TVOS_UNAVAILABLE
  #define __TVOS_UNAVAILABLE 0
#endif

#ifndef __TVOS_PROHIBITED
  #define __TVOS_PROHIBITED 0
#endif

frakman1 avatar Oct 14 '15 23:10 frakman1

This is what you wanted:

#define __TVOS_UNAVAILABLE                    __OS_AVAILABILITY(tvos,introduced=9.0)
#define __TVOS_PROHIBITED                      __OS_AVAILABILITY(tvos,introduced=9.0)

steventroughtonsmith avatar Oct 15 '15 07:10 steventroughtonsmith

Thank you ! However, just so I understand, doesn't this enable every instance of those macros instead of just enabling UIWebviews?

frakman1 avatar Oct 15 '15 12:10 frakman1

I've tried this and it works ok on simulator but when trying to run on apple tv device the web view errors return.... any ideas guys

gavla avatar Oct 15 '15 15:10 gavla

Availability.h is included in both the Simulator and device SDKs

steventroughtonsmith avatar Oct 15 '15 15:10 steventroughtonsmith

Yes, I've got it running on the device too. I made some improvements for the cursor movements (and cursor activation method on remote), and will upload to github soon!

jvanakker avatar Oct 15 '15 15:10 jvanakker

Okay, published the changes in a fork on my account.

jvanakker avatar Oct 15 '15 17:10 jvanakker

I made a quick fix to reset the cursor to the centre everytime it re-appears in the toggle. Hope it helps someone. in ViewController.m:

#define CGRectSetPos( r, x, y ) CGRectMake( x, y, r.size.width, r.size.height )

-(void)toggleMode
{
    self.cursorMode = !self.cursorMode;

    if (self.cursorMode)
    {
        self.webview.scrollView.scrollEnabled = NO;
        self.webview.userInteractionEnabled = NO;
        cursorView.hidden = NO;
        cursorView.frame = CGRectSetPos( cursorView.frame, CGRectGetMidX([UIScreen mainScreen].bounds), CGRectGetMidY([UIScreen mainScreen].bounds) );

    }
    else
    {
        self.webview.scrollView.scrollEnabled = YES;
        self.webview.userInteractionEnabled = YES;
        cursorView.hidden = YES;
    }
}

frakman1 avatar Oct 15 '15 23:10 frakman1

@jvanakker Thank you for the touchpad/cursor improvements. Nice touch. May I suggest that for the keyboard entry, you use UIKeyboardTypeEmailAddress as it adds the .com button which for some reason is missing in the UIKeyboardTypeURL type.

frakman1 avatar Oct 16 '15 15:10 frakman1

@frakman1 You're right, that's better! Will change that too in a next version, where I would also like to have page zooming. I know Apple doesn't allow any of this (for now) for the App Store, but it's still fun to play around with and make some improvements never the less.

BTW... Talking about URL input. Long text entry is still very clumsy, even with the new tvOS software (unless you would use keyboard on the remote iOS app of course). So, it would also be nice if speech (or Siri) could be used for text input like this (while spelling the letters), especially now that we have a microphone on the remote. Could't get this on my 4th gen AppleTV. Though I haven't really looked into the SDK if this is possible yet.

jvanakker avatar Oct 16 '15 23:10 jvanakker

Now Xcode 7.1 has been released whats the best way to edit Availability.h as it's locked or is it possible to put the definitions else where cheers

gavla avatar Oct 24 '15 12:10 gavla

You need to be root to change the file. Just use sudo:

sudo nano /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/Availability.h

sebastianpopp avatar Oct 29 '15 18:10 sebastianpopp

Find this: #define __TVOS_UNAVAILABLE __OS_AVAILABILITY(tvos,unavailable) #define __TVOS_PROHIBITED __OS_AVAILABILITY(tvos,unavailable)

Change to this: #define __TVOS_UNAVAILABLE_NOTQUITE __OS_AVAILABILITY(tvos,unavailable) #define __TVOS_PROHIBITED_NOTQUITE __OS_AVAILABILITY(tvos,unavailable)

CTRL+O to save changes in the Nano editor. It will ask to save to file. Press return. CTRL+X to exit the Nano editor.

If you open up Availability.h in Xcode, the lines to change should be 272 and 273. Have fun.

SteMc74 avatar Nov 06 '15 23:11 SteMc74

Really though, you are just tricking the compiler into letting you use UIWebView. But if you want to compile this app without modifying Availability.h, you can. All you really have to do is instantiate UIWebView without using the header definition. Change the defined type to id and have at it. This does mean you can't use dot notation to access UIWebView properties, though.

Class UIWebViewClass = NSClassFromString(@"UIWebView");
if (UIWebViewClass != Nil) {
    self.webview = [[UIWebViewClass alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]];

    // ...

    [[self.webview scrollView] setBounces:YES];
    [[[self.webview scrollView] panGestureRecognizer] setAllowedPressTypes:@[ @(UITouchTypeIndirect) ]];

zachhowe avatar Nov 07 '15 04:11 zachhowe

How come the cursor doesn't click on certain page areas e.g search bars, videos, etc.. Having the command to turn the cursor on/off by clicking on the remote touch area doesn't seem to play well with trying to click on page items. Any updates on the zoom or other capabilities that are being worked on?

belltechdave avatar Nov 08 '15 18:11 belltechdave

Hi, how can you change the Availability.h on the Apple TV pls ? Thanks in advance for the great work

NorfolkSR avatar Nov 09 '15 17:11 NorfolkSR

where is Availability.h file ?

marksnoopy avatar Nov 13 '15 03:11 marksnoopy

For newbies:

sudo vi /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/Availability.h

sudo vi /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/Availability.h

Huluhu avatar Nov 13 '15 04:11 Huluhu

For anyone not familiar with Availability and vi or nano, i have made a fork on my account with the elegant fix suggested by zachhowe (id + NSClassFromString).

No more Availability.h change needed.

FabioSpacagna avatar Nov 22 '15 19:11 FabioSpacagna

Does this work with WKWebView as well?

sabaggal avatar Jan 31 '16 22:01 sabaggal

@sabaggal Last I checked, WebKit.framework isn't public on tvOS, if it even exists at all.

zachhowe avatar Feb 01 '16 19:02 zachhowe

XCODE 8.0 missing “Availability.h” is currently locked because it does not support editing.

The file “Availability.h” could not be unlocked.

Could not add write permission to the parent folder because you do not own it. Try modifying the permissions of the folder in the Finder or Terminal.

HELP PLEASE

CARABALI avatar Oct 26 '16 20:10 CARABALI

As sebastianpopp commented above:

You need to be root to change the file. Just use sudo:

sudo nano /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/Availability.h

that will allow editing for the simulator Availability.h and do the same for device Availability.h

gavla avatar Oct 26 '16 20:10 gavla

With the above Availability.h change, the uiwebview loads properly, I can change its properties, etc. However I cannot seem to get UIWebViewDelegate to work. eg func webViewDidFinishLoad(_ webView: UIWebView) { print("webViewDidFinishLoad") } Is there something else needed in this regard? Thanks.

jimmyor avatar Apr 12 '17 13:04 jimmyor

@jvanakker First thanks for the browser. But after double clicking remote for pointer, and hovering over a link, a single click does nothing. So I cannot drill down from the home page. Please let me know. Thanks.

cragland92024 avatar Dec 14 '17 22:12 cragland92024

Hoping someone can help a newbie at this. Really keen to get the browser on Apple TV. I've followed all of the instructions and I still get some errors, it works great in the simulator but doesn't appear on the TV device itself. Attached a screenshot if that helps? screen shot 2018-10-05 at 11 26 49 am

noblerise avatar Oct 05 '18 01:10 noblerise

Hoping someone can help a newbie at this. Really keen to get the browser on Apple TV. I've followed all of the instructions and I still get some errors, it works great in the simulator but doesn't appear on the TV device itself. Attached a screenshot if that helps? screen shot 2018-10-05 at 11 26 49 am

Never mind! I fixed it. Turns out I didn't need the _NOTQUITE parts added. Cheers! (Y)

noblerise avatar Oct 06 '18 04:10 noblerise

@noblerise what did you end up changing to make it work? changing to this instead of _NOTQUITE didn't do the trick. Works for iOS 11.x not iOS12 #define __TVOS_UNAVAILABLE __OS_AVAILABILITY(tvos,introduced=9.0) #define __TVOS_PROHIBITED __OS_AVAILABILITY(tvos,introduced=9.0)

TamirTwina avatar Oct 07 '18 12:10 TamirTwina

Also having no luck getting this to work on the latest OS. 'UIDataDetectorTypes' is unavailable: not available on tvOS

rickschrader avatar Oct 11 '18 22:10 rickschrader

Go it to work on tvOS 12.0 in SDK 12 they've change a couple of things. UIDataDetectorTypes , and also UIWebview has added a notation API_UNAVAILABLE(tvOS). Just delete those in the required files (Xcode we'll show you given the errors you'll see)

For example here's the UIDataDetectorTypes after removing it:

typedef NS_OPTIONS(NSUInteger, UIDataDetectorTypes) {
    UIDataDetectorTypePhoneNumber                                        = 1 << 0, // Phone number detection
    UIDataDetectorTypeLink                                               = 1 << 1, // URL detection
    UIDataDetectorTypeAddress NS_ENUM_AVAILABLE_IOS(4_0)                 = 1 << 2, // Street address detection
    UIDataDetectorTypeCalendarEvent NS_ENUM_AVAILABLE_IOS(4_0)           = 1 << 3, // Event detection
    UIDataDetectorTypeShipmentTrackingNumber NS_ENUM_AVAILABLE_IOS(10_0) = 1 << 4, // Shipment tracking number detection
    UIDataDetectorTypeFlightNumber NS_ENUM_AVAILABLE_IOS(10_0)           = 1 << 5, // Flight number detection
    UIDataDetectorTypeLookupSuggestion NS_ENUM_AVAILABLE_IOS(10_0)       = 1 << 6, // Information users may want to look up
    UIDataDetectorTypeNone          = 0,               // Disable detection
    UIDataDetectorTypeAll           = NSUIntegerMax    // Enable all types, including types that may be added later
}<REMOVED HERE>;

TamirTwina avatar Oct 12 '18 07:10 TamirTwina