Skip to content

Commit 2cd128a

Browse files
authored
Add exception description for showInputMethodPicker method on iOS (#3)
Improve error stack trace by adding an exception description <img width="1285" alt="image" src="https://github.com/bamlab/react-native-app-security/assets/89008469/88b58cfe-d207-4714-a32a-1f0fe0907871">
1 parent 82fc710 commit 2cd128a

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

example/App.tsx

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useState } from "react";
2-
import { Button, Modal, StyleSheet, View } from "react-native";
31
import { SafeKeyboardDetector } from "@bam.tech/react-native-app-security";
2+
import { useState } from "react";
3+
import { Button, Modal, Platform, StyleSheet, View } from "react-native";
44

55
export default function App() {
66
const [isModalVisible, setIsModalVisible] = useState(false);
@@ -19,7 +19,12 @@ export default function App() {
1919
<Button title="fetch - valid certificates" onPress={fetchValid} />
2020
<Button title="fetch - invalid certificates" onPress={fetchInvalid} />
2121
<Button title="Is current keyboard safe?" onPress={checkIsKeyboardSafe} />
22-
<Button title="show keyboard picker" onPress={showInputMethodPicker} />
22+
{Platform.OS === "android" ? (
23+
<Button
24+
title="show keyboard picker"
25+
onPress={() => SafeKeyboardDetector.showInputMethodPicker()}
26+
/>
27+
) : null}
2328
</View>
2429
);
2530
}
@@ -66,11 +71,3 @@ const checkIsKeyboardSafe = () => {
6671
const isKeyboardSafe = SafeKeyboardDetector.isCurrentKeyboardSafe();
6772
console.warn("is Keyboard safe", isKeyboardSafe);
6873
};
69-
70-
const showInputMethodPicker = () => {
71-
try {
72-
SafeKeyboardDetector.showInputMethodPicker();
73-
} catch (error) {
74-
console.warn("showInputMethodPicker threw. Did you call it on iOS?", error);
75-
}
76-
};

ios/RNASModule.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class RNASModule: Module {
66
// There's nothing here related to SSL pinning because we use TrustKit's "auto-setup" via the config in `Info.plist`
77

88
Function("showInputMethodPicker") {() in
9-
throw RNASModuleError.methodNotImplemented
9+
throw InputMethodPickerUnavailableException()
1010
}
1111

1212
Function("isCurrentKeyboardSafe") {() in
@@ -15,6 +15,9 @@ public class RNASModule: Module {
1515
}
1616
}
1717

18-
enum RNASModuleError: Error {
19-
case methodNotImplemented
20-
}
18+
19+
internal class InputMethodPickerUnavailableException: Exception {
20+
override var reason: String {
21+
return "Method not implemented on iOS since third-party keyboards security issues are not relevant on iOS."
22+
}
23+
}

0 commit comments

Comments
 (0)