chirag04 / react-native-in-app-utils

A react-native wrapper for handling in-app payments
MIT License
890 stars 185 forks source link

Build failed on tvOS #166

Open euroclydon37 opened 6 years ago

euroclydon37 commented 6 years ago

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

chirag04 commented 6 years ago

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?

euroclydon37 commented 6 years ago

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

chirag04 commented 6 years ago

We possibly need a separate tvOS target here

euroclydon37 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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.

chirag04 commented 6 years ago

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.

euroclydon37 commented 6 years ago

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 commented 6 years ago

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

chirag04 commented 6 years ago

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?

euroclydon37 commented 6 years ago

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 commented 6 years ago

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.

chirag04 commented 6 years ago

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.

euroclydon37 commented 6 years ago

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.

chirag04 commented 6 years ago

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.

w3irdrobot commented 6 years ago

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

euroclydon37 commented 6 years ago

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.

w3irdrobot commented 6 years ago

@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.

euroclydon37 commented 6 years ago

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 commented 6 years ago

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

w3irdrobot commented 6 years ago

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

euroclydon37 commented 6 years ago

tvOS static library.

w3irdrobot commented 6 years ago

@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.