Skip to content

Commit f39878f

Browse files
Merge pull request #167 from Kommunicate-io/updated-compile-sdk-version
Add support for compileSdkVersion as per client project with default value of 34
2 parents b3f7393 + 9bb7edd commit f39878f

File tree

10 files changed

+56
-10
lines changed

10 files changed

+56
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.0.8
2+
- Added initialization code for Android and iOS.
3+
14
## 2.0.7
25
## Android
36
- Toast Message Bug Fix.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Refer to the official docs here: https://docs.kommunicate.io/docs/flutter-instal
1313
```
1414
dependencies:
1515
//other dependencies
16-
kommunicate_flutter: ^2.0.7
16+
kommunicate_flutter: ^2.0.8
1717
```
1818

1919
2. Install the package as below:

android/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ rootProject.allprojects {
2525
apply plugin: 'com.android.library'
2626

2727
android {
28-
compileSdkVersion 33
29-
28+
def sdkProp = rootProject.findProperty('compileSdkVersion')
29+
def sdk = (sdkProp instanceof Number) ? (sdkProp as Integer) : Integer.parseInt((sdkProp ?: 34).toString())
30+
compileSdkVersion sdk
3031
defaultConfig {
3132
minSdkVersion 16
33+
targetSdkVersion sdk
3234
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3335
}
34-
lintOptions {
35-
disable 'InvalidPackage'
36-
}
36+
lintOptions { disable 'InvalidPackage' }
3737
namespace "io.kommunicate.kommunicate_flutter_plugin"
3838
}
3939

android/src/main/java/io/kommunicate/kommunicate_flutter_plugin/KmMethodHandler.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ public KmMethodHandler(Activity context) {
6666
public void onMethodCall(MethodCall call, final Result result) {
6767
if (call.method.equals("getPlatformVersion")) {
6868
result.success("Android " + android.os.Build.VERSION.RELEASE);
69+
} else if (call.method.equals("init")) {
70+
try {
71+
final String initAppID = (String) call.arguments();
72+
if (TextUtils.isEmpty(initAppID)) {
73+
result.error(ERROR, "appId is missing", null);
74+
return;
75+
}
76+
Kommunicate.init(context, initAppID);
77+
result.success(null);
78+
} catch (Exception e) {
79+
result.error(ERROR, e.toString(), null);
80+
}
6981
} else if (call.method.equals("setServerConfiguration")) {
7082
try {
7183
String serverConfigText = (String) call.arguments();

example/lib/home.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
22
import 'package:flutter/material.dart';
33
import 'package:intl/intl.dart';
44
import 'package:kommunicate_flutter/kommunicate_flutter.dart';
5+
import 'package:kommunicate_flutter_plugin_example/AppConfig.dart';
56
import 'dart:io' show Platform;
67
import 'main.dart';
78

@@ -17,6 +18,11 @@ class HomePageState extends State<HomePage> {
1718
void initState() {
1819
try {} catch (e) {}
1920
super.initState();
21+
KommunicateFlutterPlugin.init(AppConfig.APP_ID).then((value) {
22+
print("Initialization successful : " + value.toString());
23+
}).catchError((error) {
24+
print("Initialization error occurred : " + error.toString());
25+
});
2026
}
2127

2228
@override

example/lib/main.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class _MyAppState extends State<MyApp> {
4343
});
4444
}
4545
super.initState();
46+
KommunicateFlutterPlugin.init(AppConfig.APP_ID).then((value) {
47+
print("Initialization successful : " + value.toString());
48+
}).catchError((error) {
49+
print("Initialization error occurred : " + error.toString());
50+
});
4651
}
4752

4853
@override

example/pubspec.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ packages:
4545
dependency: "direct main"
4646
description:
4747
name: cupertino_icons
48-
sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
48+
sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
4949
url: "https://pub.dev"
5050
source: hosted
51-
version: "1.0.6"
51+
version: "1.0.8"
5252
fake_async:
5353
dependency: transitive
5454
description:
@@ -86,7 +86,7 @@ packages:
8686
path: ".."
8787
relative: true
8888
source: path
89-
version: "2.0.7"
89+
version: "2.0.8"
9090
leak_tracker:
9191
dependency: transitive
9292
description:

ios/Classes/SwiftKommunicateFlutterPlugin.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ public class SwiftKommunicateFlutterPlugin: NSObject, FlutterPlugin, KMPreChatFo
5656
} else {
5757
Kommunicate.setServerConfiguration(.defaultConfiguration)
5858
}
59+
} else if(call.method == "init") {
60+
guard let rawAppId = call.arguments as? String else {
61+
self.sendErrorResultWithCallback(result: result, message: "Missing appId")
62+
return
63+
}
64+
65+
let appId = rawAppId.trimmingCharacters(in: .whitespacesAndNewlines)
66+
67+
guard !appId.isEmpty else {
68+
self.sendErrorResultWithCallback(result: result, message: "Invalid or empty appId")
69+
return
70+
}
71+
72+
Kommunicate.setup(applicationId: appId)
73+
self.appId = appId
74+
self.sendSuccessResultWithCallback(result: result, message: "Successfully initialized with appId: \(appId)")
5975
} else if(call.method == "isLoggedIn") {
6076
result(Kommunicate.isLoggedIn)
6177
} else if(call.method == "login") {

lib/kommunicate_flutter.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class KommunicateFlutterPlugin {
1313
return version;
1414
}
1515

16+
static Future<dynamic> init(String appId) async {
17+
return await _channel.invokeMethod('init', appId);
18+
}
19+
1620
static Future<dynamic> buildConversation(dynamic conversationObject) async {
1721
if (kIsWeb) {
1822
return await _channel.invokeMethod('buildConversation', jsonEncode(conversationObject));

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: kommunicate_flutter
22
description: Flexible, lightweight, and easily integrable Flutter SDK for Kommunicate AI chatbot & Live Chat.
3-
version: 2.0.7
3+
version: 2.0.8
44
homepage: https://kommunicate.io
55

66
environment:

0 commit comments

Comments
 (0)