09-28-2020 06:27 - edited 09-28-2020 08:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-28-2020 06:27 - edited 09-28-2020 08:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
My companion app used some network calls to handle OAuth. I noticed that it worked fine in Android and in the Simulator, but failed on iOS.
After connecting an iPhone to the developer bridge, I saw error messages stating the btoa function could not be found. This was surprising since that is supposed to be a global function. I was able to resolve this by adding `buffer` as a dependency and writing my own version of the function.
I kept debugging and also noticed that FormData was not generating the appropriate string in my request bodies. While adding `form-data` or `formdata-node` as dependencies caused more headaches than intended, a hard-coded approach to setting up those request bodies got around the error.
Setting aside the steps I took to resolve these issues, why was this even a problem in iOS? It took me a while to get my hands on an iOS device for testing and have seen support tickets raised during this time due to broken behavior. If companion apps in iOS behave differently than in the simulator and/or Android, those underlying differences should be made upfront so that developers can address them with limited hardware support.
09-29-2020 02:53
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


09-29-2020 02:53
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks for the feedback, I've created a ticket for the iOS team to address these bugs.
If you can provide some small code samples of the issues, that would be a great help for them.

09-29-2020 03:47 - edited 09-29-2020 12:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-29-2020 03:47 - edited 09-29-2020 12:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I don't know the breadth of this issue, but these were the items that gave me trouble:
- btoa()
- Buffer
- FormData/URLSearchParams
On iOS, when either of the first two were encountered, an error was generated that simply stated they could not be found.
btoa(`${CLIENT_ID}:${CLIENT_SECRET}`)
Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString('base64')
I didn't dig deep on the last one, but all requests made by the Fetch API failed. Originally, I had used the following to generate the request body:
const formData = new FormData();
formData.append(key, value);
const body = new URLSearchParams(formData).toString();
I had to switch it to the following pattern:
const formData = [];
formData.push(`key=${value}`);
const body = formData.join('&');
Either something in FormData or the URLSearchParams was generating an invalid body. I wasn't thrilled about my fix as it doesn't handle escaping, but it did the job.

09-30-2020 04:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-30-2020 04:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks again for looking into this, @JonFitbit. I was finally able to roll out a corrected version of our app to work around the above issues.
Our app has suffered in ratings due to this bug and not having immediate access to an iOS device to correct what was observed. While I think reviews will be more positive in the future due to the update, I don't think this will help fix the reviews from users who encountered this behavior in iOS. I would be happy to chat in PM's about any possible resolution to this given the nature of this iOS bug.

