react-native-in-app-utils icon indicating copy to clipboard operation
react-native-in-app-utils copied to clipboard

Build failed on tvOS

Open euroclydon37 opened this issue 7 years ago • 23 comments

I get the following error:

error: no such file or directory: '/Users/Jeremy/Library/Developer/Xcode/DerivedData/myapp-eqgygqlzhxidzyclmlhhwylnuhyx/Build/Products/Debug-appletvos/libInAppUtils.a'

I've linked all the libraries per these instructions

euroclydon37 avatar Mar 28 '18 19:03 euroclydon37

We never tested this on tvOS. You will probably have to debug this. Feel free to send it a PR if you get this working.

From the error message, it looks like you need to goto App settings -> Build phases -> Link libraries and add libInAppUtils.a?

chirag04 avatar Mar 28 '18 21:03 chirag04

I've linked the libraries. I'll tinker around with it and see if I can figure it out.

euroclydon37 avatar Mar 29 '18 13:03 euroclydon37

We possibly need a separate tvOS target here

chirag04 avatar Mar 29 '18 14:03 chirag04

I added a tvOS target, and everything builds just fine. But the loadProducts method never calls back. Neither success nor failure.

I'm not very fluent in Swift or Objective C, so I'm a bit handicapped at looking into this. Javascript is my world. But this issue is holding up my work, so I'll be throwing my best at it.

Just be ready to help me, if you can. =]

euroclydon37 avatar Apr 02 '18 14:04 euroclydon37

I feel like an idiot. Lol

When I added a tvOS target, it just created boilerplate header and m file.

I copied the source files from the iOS target over and it's up and running. I printed a string from the loadProducts function.

However, the callback was never run. I know this because I'm console.logging within the callback, whether error or success.

euroclydon37 avatar Apr 02 '18 19:04 euroclydon37

Phew. So after a day of cramming Objective C into my brain, I've discovered that the delegate methods aren't being called. I added requestDidFinish to the mix just to make sure. All it's doing is logging a string. I never see that string.

loadProducts is being called. I just never hear from any of the delegate methods didReceiveResponse, request:didFailWithError, or requestDidFinish.

I have to push through this for what I'm working on, but any help would be greatly appreciated.

euroclydon37 avatar Apr 03 '18 20:04 euroclydon37

I suggest adding three breakpoints in xcode:

  1. https://github.com/chirag04/react-native-in-app-utils/blob/2845d194f906d4c60dd8393e941141c45689aa72/InAppUtils/InAppUtils.m#L178
  2. https://github.com/chirag04/react-native-in-app-utils/blob/2845d194f906d4c60dd8393e941141c45689aa72/InAppUtils/InAppUtils.m#L206
  3. https://github.com/chirag04/react-native-in-app-utils/blob/2845d194f906d4c60dd8393e941141c45689aa72/InAppUtils/InAppUtils.m#L234

You should see two of those branches getting hit. Should be able to trace it from there.

chirag04 avatar Apr 03 '18 21:04 chirag04

Sweet. I'm exploring this. Just an FYI, those are on lines 199, 229, and 258 for me. And all I've added are about 7 lines with requiresMainQueueSetup and some logging.

euroclydon37 avatar Apr 04 '18 14:04 euroclydon37

After the first breakpoint, nothing else happens. No apparent errors.

euroclydon37 avatar Apr 04 '18 15:04 euroclydon37

that's weird. atleast one more callback should be executed. is this returning true for you: https://github.com/chirag04/react-native-in-app-utils/blob/2845d194f906d4c60dd8393e941141c45689aa72/InAppUtils/InAppUtils.m#L187?

chirag04 avatar Apr 04 '18 16:04 chirag04

It is.

Is this SO answer informative at all? It seems like you shouldn't have to persist the request in a class variable, right? I might try it still out of desperation. lol

Again, thanks for helping out with this.

euroclydon37 avatar Apr 04 '18 16:04 euroclydon37

That worked. Persisting the request on the class gets me a response. Not sure what the right approach is moving forward. It doesn't seem right to have each request type persisted as a class variable.

What would you suggest?

EDIT: Apple's documentation shows them persisting the request on the class.

euroclydon37 avatar Apr 04 '18 16:04 euroclydon37

Ok. I think i understand the problem here. Sounds like the request is getting dumped since we don't have a strong reference to it. I think others have reported similar issues in the past.

I can think of storing the requests in a map of something just like the callback map we have.

chirag04 avatar Apr 04 '18 21:04 chirag04

That sounds like a good idea to me. Do you plan on working on it pretty quickly or should I take on the endeavor? I'm gonna need it fixed pretty soon for work, so it aligns with my goals at the moment.

euroclydon37 avatar Apr 05 '18 23:04 euroclydon37

i don't have plans to work on it anytime soon and would def encourage you to continue on this. Feel free to send a PR when you have it work. Thanks @euroclydon37 for pushing it through.

chirag04 avatar Apr 06 '18 15:04 chirag04

@euroclydon37 have you done any work on this? I think I am having this same issue.

w3irdrobot avatar May 15 '18 21:05 w3irdrobot

I have it working, but I haven't been able to put a pull request together, yet, because of work. I just added a tvOS target and named it InAppUtils_tvOS. I then copied all of the .h and .m files into the resulting tvOS folder.

Then, I added an SKProductsRequest variable to the class. (I'm only lightly familiar with Objective C)

@implementation InAppUtils
{
    NSArray *products;
    NSMutableDictionary *_callbacks;
    SKProductsRequest *productsRequest;  # Added this line
}

Then I changed the loadProducts method to use that variable instead of a local one.

RCT_EXPORT_METHOD(loadProducts:(NSArray *)productIdentifiers
                  callback:(RCTResponseSenderBlock)callback)
{
    # Altered this line
    self -> productsRequest = [[SKProductsRequest alloc]
                                          initWithProductIdentifiers:[NSSet setWithArray:productIdentifiers]];
    productsRequest.delegate = self;
    _callbacks[RCTKeyForInstance(productsRequest)] = callback;
    [productsRequest start];
}

It's a total hack, and not the final way it needs to be fixed. But I don't have the time available to invest in a legit fix at the moment. I'm the only developer at this company. lol

I hope this helps you.

euroclydon37 avatar May 16 '18 13:05 euroclydon37

@euroclydon37 Could you give more information on how you created the new tvOS target? I'm getting lost in all the options and am not familiar at all with the correct way to do things in Xcode.

w3irdrobot avatar May 16 '18 17:05 w3irdrobot

In the file browser to the on the left side of Xcode (make sure the left pane is out, buttons are in top right), click your project name at the top. Within the center pane, you should see a section toward the left that has a Project section and a *Targets section. At the bottom of that section (where you see a filter input), you'll see a plus. That's where you add a tvOS target.

euroclydon37 avatar May 16 '18 20:05 euroclydon37

I'll post some pictures in the morning if you haven't figured it out.

euroclydon37 avatar May 16 '18 20:05 euroclydon37

I appreciate the help. I found all that. The issue I'm having is deciding which "template" is the correct tvOS template to use.

w3irdrobot avatar May 16 '18 20:05 w3irdrobot

tvOS static library.

euroclydon37 avatar May 16 '18 22:05 euroclydon37

@euroclydon37 I appreciate all the help. It worked! The last piece I had to do was make sure that the new tvOS library was linked into the tvOS target for my application.

w3irdrobot avatar May 18 '18 11:05 w3irdrobot