react-native-ble-advertiser icon indicating copy to clipboard operation
react-native-ble-advertiser copied to clipboard

Unable to execute on IOS

Open ashok-sl opened this issue 4 years ago • 11 comments

I am stuck with the following issue. Can't even run a sample setup. Platform - IOS xCode Version - 12.3 Device - iPad

Screenshot 2021-01-13 at 5 43 44 PM

ashok-sl avatar Jan 13 '21 12:01 ashok-sl

Hum... I have never tested on an iPad. Have you tried running on a simulator just to see if it goes through?

vitorpamplona avatar Jan 13 '21 14:01 vitorpamplona

Yes, First I tried with iPhone 11 simulator but there also the same error.

ashok-sl avatar Jan 13 '21 15:01 ashok-sl

Hi, I had the same issue ... try to find additional info on why it failed. I can't remember where but I found that explanation and as I remember it was because of "Privacy - Bluetooth Peripheral Usage Description" was missing in Info.plist

milosh86 avatar Mar 15 '21 09:03 milosh86

Version 0.0.17 released. It seems to be working well on my devices. Let me know if you see any issues.

vitorpamplona avatar Sep 27 '22 15:09 vitorpamplona

@vitorpamplona Still not working on the iOS device. Getting "BLEAdvertiser.<function_name> is not a function." Please help :)

jole141 avatar Feb 09 '23 14:02 jole141

For some reason, you need to add below entry into your Podfile manually to make it work. Put it inside your app target, then run pod install

pod 'react-native-ble-advertiser', :path => '../node_modules/react-native-ble-advertiser/ios'

maulanakurniawan avatar Mar 30 '23 20:03 maulanakurniawan

For some reason, you need to add below entry into your Podfile manually to make it work. Put it inside your app target, then run pod install

pod 'react-native-ble-advertiser', :path => '../node_modules/react-native-ble-advertiser/ios'

Based off this fix highlighted by @maulanakurniawan , here is how you'd implement this in an expo managed project.

  1. Create a file somewhere in your project. Ex: custom-plugins/react-native-ble-advertiser.js and paste the code below in it.
const { withDangerousMod } = require('@expo/config-plugins');
const { mergeContents } = require('@expo/config-plugins/build/utils/generateCode');
const fs = require('fs');
const path = require('path');

function withPodfile(config) {
	return withDangerousMod(config, [
		'ios',
		async config => {
			const filePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
			const contents = fs.readFileSync(filePath, 'utf-8');

			const addedPod = mergeContents({
				tag: 'Add the BLEAdvertiser pod',
				src: contents,
				newSrc: `pod 'react-native-ble-advertiser', :path => '../node_modules/react-native-ble-advertiser/ios'`,
				anchor: 'use_expo_modules!',
				offset: 0,
				comment: '#'
			});

			if (!addedPod.didMerge) {
				console.log(
					"ERROR: Cannot add BLEAdvertiser pod the project's ios/Podfile because it's malformed. Please report this with a copy of your project Podfile."
				);
				return config;
			}

			fs.writeFileSync(filePath, addedPod.contents);

		return config;
		}
	]);
}

module.exports = function withBLEAdvertiserPodFix(config) {
	config = withPodfile(config);
	return config;
};

Then in your expo config file, add the following under expo.plugins

{
    "expo": {
         "plugins": [
            ...,
            "./custom-plugins/react-native-ble-advertiser.js"
        ]
    }
}

Kasendwa avatar Apr 23 '23 23:04 Kasendwa

@Kasendwa, please help me to setup Expo project with this package (react-native-ble-advertiser). Does your solution work also on Android? If not, could you please provide a minimal Expo project with this package working on both iOS and Android? It is really a big dream for me to make it possible with the simple flow of Expo (Without the need of Android Studio and Mac XCode).

Here: https://github.com/vitorpamplona/react-native-ble-advertiser/pull/55 @fhllnd did a great job by providing the bare React Native working minimal project (it is updated example project, because the old example project no longer works), and it seems very useful and informative code even if I somehow manage to setup react-native-ble-advertiser with Expo.

I was going to go with bare React Native flow, but I discovered that nowadays Expo became too powerful to ignore. It no longer needs ejecting and it can just implement unsupported npm packages by config plugins (like your solution) and/or development builds and/or creating native modules. The thing is that I am still very new to RN world and I feel I need a little help to implement this package as a config plugin (or something like that), just to get the minimal project setup.

leodevbro avatar Aug 12 '23 09:08 leodevbro

Hi @leodevbro, sorry I had missed this. Let me look into it tomorrow and get back to you.

Kasendwa avatar Aug 17 '23 19:08 Kasendwa

Hi @leodevbro, sorry I had missed this. Let me look into it tomorrow and get back to you.

Oh, it's ok. Thanks. Sure, I can wait many days or many weeks. I'm just trying to at least find out if this is possible without a big headache.

leodevbro avatar Aug 17 '23 20:08 leodevbro

@Kasendwa, Hi again, just wanted to ask, have you had any opportunity to have a look at it? I understand if you have limited time.

leodevbro avatar Aug 29 '23 13:08 leodevbro