Custom written iOS native module not exported - ios

As my title says, I created a bare bones iOS native module in react native and it is not appearing in the final NativeModules javascript object. Here's exactly what I'm doing. I'm pretty stumped by this.
Create fresh project with react-native init testproj
Open ios folder of testproj in xcode and create a Cocoa Touch Class called MyModule
In MyModule.h I have the following:
#import <React/RCTBridgeModule.h>
#interface MyModule : NSObject <RCTBridgeModule>
#end
In MyModule.m I have the following:
#import "MyModule.h"
#implementation MyModule
RCT_EXPORT_MODULE()
#end
I run react-native run-ios and the app builds successfully. When printing out the NativeModules like so:
import React, {Component} from 'react';
import {NativeModules} from 'react-native'
export default class App extends Component {
componentWillMount() {
console.log('my modules! ', NativeModules)
}
render() {
...
}
}
I don't see MyModule in the console logs but I see all of the base react native modules.
Does anyone have any ideas as to why this would happen? Is there something I'm missing in the xcode build phase? For more context, these are the relevant versions:
xcode 9.4.1
react 16.4.0
react-native 0.55.4
Running on iPhone 6 - 11.4 simulator

React Native will not expose your native module if it doesn't have any methods.
You need to export at least one method using the RCT_EXPORT_METHOD (or RCT_REMAP_METHOD) macro before you will be able to access it.

Related

Why is TestFlight app different from local development?

I have a React Native app with a custom native plugin.
The app works fine when I test it with Xcode on my device.
I uploaded the exact same app to the App Store and it got broken.
On my iPhone it doesn't actually start and on my iPad it is buggy:
I have to tap buttons twice
Code order is wrong (may threading / rendering)
Events from the plugin sometimes get fired and sometimes not. Totally random. (could also be rendering issue)
Unfortunately, I can't debug the TestFlight App.
Does someone have a starting point why this could happen?
I found the problem. It was in my Plugin and how I expose it. My index.ts file looked like this:
import { NativeModules } from 'react-native';
const { MyPlugin } = NativeModules;
export default MyPlugin;
Better with no default export:
import { NativeModules } from 'react-native';
export const { MyPlugin } = NativeModules;
I don't know why a default export doesn't work in release mode. I tried all release flags to be the same as default, but it was the same result.
So, just changing the way of export was fixing it.

Conditional Imports in Swift not working?

I want to use a module (SwiftyStoreKit) which has a minimum requirement of WatchOS 6.2, however I don't want to increase my WatchOS target because I don't want to lose support for older watches. My understanding is that Swift now has conditional imports which will let you import a module only in the OS allows the import but the below code is not working? I'm still getting a compiling error "Compiling for watchOS 4.3, but module 'SwiftyStoreKit' has a minimum deployment target of watchOS 6.2:" and if I remove "import SwiftyStoreKit" the module isn't detected.
#if canImport(SwiftyStoreKit)
import SwiftyStoreKit
class SwiftyStoreKitWatchHelper {
}
#endif
Try this
#if canImport(SwiftyStoreKit)
import SwiftyStoreKit
#endif
#available(watchOS 6.2)
class SwiftyStoreKitWatchHelper {
}

react-native-camera for iOS doesn't work with latest react-native v0.49

i'm trying to build my project on XCode with IPhone 6 IOS v11.0 in react native latest version v0.49 after installing react-native-camera and it failed.
I get the error
Redefinition of 'RCTMethodInfo'
typedef struct RCTMethodInfo {
const char *const jsName;
const char *const objcName;
const BOOL isSync;
} RCTMethodInfo;
I also faced the same issue, I hope it would help you out
Just open project in Xcode and search globally for "RCTBridgeModule.h"
and you will get 4 to 5 files , so just open your third party camera file
and replace
import "RCTBridgeModule.h" with #import <React/RCTBridgeModule.h>

Initialization Errors with React Native Tutorials

I just installed React Native, and am attempting to follow tutorials on the React Native website to get accustomed to it. However every tutorial I end up doing just gives me a big red error screen in the iOS Simulator.
As an example, I followed the "Hello World" tutorial on the React Native website
import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';
class HelloWorldApp extends Component {
render() {
return (
<Text>Hello world!</Text>
);
}
}
AppRegistry.registerComponent('HelloWorldApp', () => HelloWorldApp);
but am met with this error after compiling and running in the simulator"
"Application TestProject has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent"
I'm confused because I know nothing yet about RN, am following their tutorials to the letter, and am getting errors.
Please advise?
There might be two possibilities as I know of:
When you run react-native run-ios the packager didn't start automatically. If that's the case, Run the Packager Manually. To do so:
In one Tab of your terminal run react-native start and in another run react-native run-ios.
Or while following the document from react native's site, you might have changed the app's name. Like:
You created a project using react-native init AwesomeProject. The Project's name here is AwesomeProject.
And then changed your default index.ios.js and replaced the Component's name with HelloWorldApp.
class HelloWorldApp extends Component
AppRegistry.registerComponent('HelloWorldApp', () => HelloWorldApp);

Swift and Salesforce IOS SDK

I am trying to create a connected app with Salesforce IOS SDK and Swift and followed the steps mentioned in the https://www.youtube.com/watch?v=9Mt02DzsOBo but as try to attach the "Appname-Swift.h"file in the AppDelegate.m file I am getting an error.Please help what can be done next.
1)I have created the native connected app as per Salesforce IOS
Description
2)Created the bridge for Swift
"MySampleApp-Bridging-Header.h"
3)Added SFRestDelegate to RootVC.Swift
4)Imported the important header files to
"mySampleApp-bridging-Header.h" that is
#import <UIKit/UIKit.h>
#import "SFRestAPI.h"
5)As soon I am trying to import #import "MySampleApp-Swift.h" I am getting the error
I am using OSX mavericks with XCode-6(4beta)
I don't think in the video or in the sample code repository there is a file named MySampleApp-Swift.h

Resources