Skip to content

Commit b773591

Browse files
author
spoeck
committed
feat: add iOS support
- add api-ai js sdk - use system text-to-speech - update example app
1 parent f5ca368 commit b773591

15 files changed

Lines changed: 450 additions & 112 deletions

File tree

example/App.js

Lines changed: 0 additions & 84 deletions
This file was deleted.

example/index.android.js

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,81 @@
11

2+
import React, { Component } from 'react';
23
import {
3-
AppRegistry,
4+
AppRegistry,
5+
StyleSheet,
6+
Text,
7+
View,
8+
Button
49
} from 'react-native';
510

6-
import App from './App';
11+
import ApiAi from "react-native-api-ai"
712

8-
AppRegistry.registerComponent('ApiAiExample', () => App);
13+
export default class App extends Component {
14+
constructor(props) {
15+
super(props);
16+
17+
this.state = {
18+
result: "",
19+
listeningState: "not started",
20+
audioLevel: 0,
21+
};
22+
23+
console.log(ApiAi);
24+
25+
ApiAi.setConfiguration(
26+
"INSERT_YOUR_CLENT_ACCESS_TOKEN_HERE", ApiAi.LANG_GERMAN
27+
);
28+
}
29+
30+
31+
render() {
32+
return (
33+
<View style={styles.container}>
34+
35+
<View style={{flex: 4}}>
36+
<Text>{"Listening State: " + this.state.listeningState}</Text>
37+
<Text>{"Audio Level: " + this.state.audioLevel}</Text>
38+
<Text>{"Result: " + this.state.result}</Text>
39+
</View>
40+
<View style={{flex: 1, padding: 10}}>
41+
<Button title="Start Listening" onPress={() => {
42+
43+
44+
ApiAi.onListeningStarted(() => {
45+
this.setState({listeningState: "started"});
46+
});
47+
48+
ApiAi.onListeningCanceled(() => {
49+
this.setState({listeningState: "canceled"});
50+
});
51+
52+
ApiAi.onListeningFinished(() => {
53+
this.setState({listeningState: "finished"});
54+
});
55+
56+
ApiAi.onAudioLevel(level => {
57+
this.setState({audioLevel: level});
58+
});
59+
60+
ApiAi.startListening(result => {
61+
this.setState({result: result});
62+
}, error => {
63+
this.setState({result: error});
64+
});
65+
66+
}}/>
67+
</View>
68+
</View>
69+
);
70+
}
71+
}
72+
73+
const styles = StyleSheet.create({
74+
container: {
75+
flex: 1,
76+
backgroundColor: '#F5FCFF',
77+
},
78+
79+
});
80+
81+
AppRegistry.registerComponent('ApiAiExample', () => App);

example/index.ios.js

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,68 @@
11

2+
import React, { Component } from 'react';
23
import {
3-
AppRegistry,
4+
AppRegistry,
5+
StyleSheet,
6+
Text,
7+
View,
8+
Button
49
} from 'react-native';
510

6-
import App from './App';
11+
import ApiAi from "react-native-api-ai"
12+
13+
export default class App extends Component {
14+
constructor(props) {
15+
super(props);
16+
17+
this.state = {
18+
result: "",
19+
buttonText: "Start Listening",
20+
listening: false
21+
};
22+
23+
console.log(ApiAi);
24+
25+
ApiAi.setConfiguration(
26+
"INSERT_YOUR_CLENT_ACCESS_TOKEN_HERE", ApiAi.LANG_GERMAN
27+
);
28+
}
29+
30+
31+
render() {
32+
return (
33+
<View style={styles.container}>
34+
35+
<View style={{flex: 4}}>
36+
<Text>{"Result: " + this.state.result}</Text>
37+
</View>
38+
<View style={{flex: 1, padding: 10}}>
39+
<Button title={this.state.buttonText} onPress={() => {
40+
41+
if (this.state.listening) {
42+
ApiAi.finishListening();
43+
this.setState({buttonText: "Start Listening", listening: false})
44+
} else {
45+
ApiAi.startListening(result => {
46+
this.setState({result: JSON.stringify(result)});
47+
}, error => {
48+
this.setState({result: JSON.stringify(error)});
49+
});
50+
this.setState({buttonText: "Stop Listening", listening: true})
51+
}
52+
}}/>
53+
</View>
54+
</View>
55+
);
56+
}
57+
}
58+
59+
const styles = StyleSheet.create({
60+
container: {
61+
flex: 1,
62+
paddingTop: 20,
63+
backgroundColor: '#F5FCFF',
64+
},
65+
66+
});
767

868
AppRegistry.registerComponent('ApiAiExample', () => App);

example/ios/ApiAiExample.xcodeproj/project.pbxproj

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
};
66
objectVersion = 46;
77
objects = {
8+
89
/* Begin PBXBuildFile section */
910
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; };
1011
00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; };
@@ -36,7 +37,7 @@
3637
2DCD954D1E0B4F2C00145EB5 /* ApiAiExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* ApiAiExampleTests.m */; };
3738
5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */; };
3839
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
39-
7DA4A8C1EA4946188458570E /* libApiAi.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E5FF57766704A70B9C2E4A4 /* libApiAi.a */; };
40+
8FA3D145624B4E6F9607C6F0 /* libApiAi.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37B297C26B4C4FCDB4E17D61 /* libApiAi.a */; };
4041
/* End PBXBuildFile section */
4142

4243
/* Begin PBXContainerItemProxy section */
@@ -229,6 +230,20 @@
229230
remoteGlobalIDString = 58B5119B1A9E6C1200147676;
230231
remoteInfo = RCTText;
231232
};
233+
8427736E1F2CDF9A00EA2752 /* PBXContainerItemProxy */ = {
234+
isa = PBXContainerItemProxy;
235+
containerPortal = 6704C2EF9C514029A6CC19F3 /* ApiAi.xcodeproj */;
236+
proxyType = 2;
237+
remoteGlobalIDString = CDD7BF781B2D5125006FDA75;
238+
remoteInfo = ApiAi;
239+
};
240+
842773701F2CDF9A00EA2752 /* PBXContainerItemProxy */ = {
241+
isa = PBXContainerItemProxy;
242+
containerPortal = 6704C2EF9C514029A6CC19F3 /* ApiAi.xcodeproj */;
243+
proxyType = 2;
244+
remoteGlobalIDString = CDD7BF831B2D5126006FDA75;
245+
remoteInfo = ApiAiTests;
246+
};
232247
/* End PBXContainerItemProxy section */
233248

234249
/* Begin PBXFileReference section */
@@ -253,12 +268,12 @@
253268
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
254269
2D02E47B1E0B4A5D006451C7 /* ApiAiExample-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ApiAiExample-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
255270
2D02E4901E0B4A5D006451C7 /* ApiAiExample-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ApiAiExample-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
271+
37B297C26B4C4FCDB4E17D61 /* libApiAi.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libApiAi.a; sourceTree = "<group>"; };
256272
5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; };
273+
6704C2EF9C514029A6CC19F3 /* ApiAi.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = ApiAi.xcodeproj; path = "../node_modules/react-native-api-ai/ios/ApiAi.xcodeproj"; sourceTree = "<group>"; };
257274
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
258275
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
259276
8EF487BE334B46679F07D7A7 /* libRCTActionSheet.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRCTActionSheet.a; sourceTree = "<group>"; };
260-
6A8ABB3E25E149CA93B4D814 /* ApiAi.xcodeproj */ = {isa = PBXFileReference; name = "ApiAi.xcodeproj"; path = "../node_modules/react-native-api-ai/ios/ApiAi.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
261-
0E5FF57766704A70B9C2E4A4 /* libApiAi.a */ = {isa = PBXFileReference; name = "libApiAi.a"; path = "libApiAi.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
262277
/* End PBXFileReference section */
263278

264279
/* Begin PBXFrameworksBuildPhase section */
@@ -286,7 +301,7 @@
286301
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
287302
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
288303
0FD5BCB5BC524329B7161A66 /* libRCTActionSheet.a in Frameworks */,
289-
7DA4A8C1EA4946188458570E /* libApiAi.a in Frameworks */,
304+
8FA3D145624B4E6F9607C6F0 /* libApiAi.a in Frameworks */,
290305
);
291306
runOnlyForDeploymentPostprocessing = 0;
292307
};
@@ -453,7 +468,7 @@
453468
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */,
454469
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
455470
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
456-
6A8ABB3E25E149CA93B4D814 /* ApiAi.xcodeproj */,
471+
6704C2EF9C514029A6CC19F3 /* ApiAi.xcodeproj */,
457472
);
458473
name = Libraries;
459474
sourceTree = "<group>";
@@ -490,6 +505,15 @@
490505
name = Products;
491506
sourceTree = "<group>";
492507
};
508+
842773681F2CDF9900EA2752 /* Products */ = {
509+
isa = PBXGroup;
510+
children = (
511+
8427736F1F2CDF9A00EA2752 /* libApiAi.a */,
512+
842773711F2CDF9A00EA2752 /* ApiAiTests.xctest */,
513+
);
514+
name = Products;
515+
sourceTree = "<group>";
516+
};
493517
/* End PBXGroup section */
494518

495519
/* Begin PBXNativeTarget section */
@@ -578,6 +602,9 @@
578602
CreatedOnToolsVersion = 6.2;
579603
TestTargetID = 13B07F861A680F5B00A75B9A;
580604
};
605+
13B07F861A680F5B00A75B9A = {
606+
DevelopmentTeam = 9Q67564RV9;
607+
};
581608
2D02E47A1E0B4A5D006451C7 = {
582609
CreatedOnToolsVersion = 8.2.1;
583610
ProvisioningStyle = Automatic;
@@ -601,6 +628,10 @@
601628
productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */;
602629
projectDirPath = "";
603630
projectReferences = (
631+
{
632+
ProductGroup = 842773681F2CDF9900EA2752 /* Products */;
633+
ProjectRef = 6704C2EF9C514029A6CC19F3 /* ApiAi.xcodeproj */;
634+
},
604635
{
605636
ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */;
606637
ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */;
@@ -832,11 +863,18 @@
832863
remoteRef = 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */;
833864
sourceTree = BUILT_PRODUCTS_DIR;
834865
};
835-
848971321F2A135A00FA2F32 /* ApiAiTests.xctest */ = {
866+
8427736F1F2CDF9A00EA2752 /* libApiAi.a */ = {
867+
isa = PBXReferenceProxy;
868+
fileType = archive.ar;
869+
path = libApiAi.a;
870+
remoteRef = 8427736E1F2CDF9A00EA2752 /* PBXContainerItemProxy */;
871+
sourceTree = BUILT_PRODUCTS_DIR;
872+
};
873+
842773711F2CDF9A00EA2752 /* ApiAiTests.xctest */ = {
836874
isa = PBXReferenceProxy;
837875
fileType = wrapper.cfbundle;
838876
path = ApiAiTests.xctest;
839-
remoteRef = 848971311F2A135A00FA2F32 /* PBXContainerItemProxy */;
877+
remoteRef = 842773701F2CDF9A00EA2752 /* PBXContainerItemProxy */;
840878
sourceTree = BUILT_PRODUCTS_DIR;
841879
};
842880
/* End PBXReferenceProxy section */
@@ -1036,6 +1074,7 @@
10361074
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
10371075
CURRENT_PROJECT_VERSION = 1;
10381076
DEAD_CODE_STRIPPING = NO;
1077+
DEVELOPMENT_TEAM = 9Q67564RV9;
10391078
HEADER_SEARCH_PATHS = (
10401079
"$(inherited)",
10411080
"$(SRCROOT)..",
@@ -1064,6 +1103,7 @@
10641103
buildSettings = {
10651104
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
10661105
CURRENT_PROJECT_VERSION = 1;
1106+
DEVELOPMENT_TEAM = 9Q67564RV9;
10671107
HEADER_SEARCH_PATHS = (
10681108
"$(inherited)",
10691109
"$(SRCROOT)..",

0 commit comments

Comments
 (0)