From 45b28cc0a80d8f411d5c9449a9d2013cacac845f Mon Sep 17 00:00:00 2001 From: Xiaowei Zhu <33129495+zhu-xiaowei@users.noreply.github.com> Date: Thu, 25 Apr 2024 18:44:49 +0800 Subject: [PATCH] fix: the issue when initialize SDK without global attribute (#11) Co-authored-by: zhu-xiaowei --- example/lib/main.dart | 20 ++++++++++++++++++++ ios/Classes/ClickstreamFlutterPlugin.swift | 3 +-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 83d4062..3e566f9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -58,6 +58,18 @@ class _MyAppState extends State { log("init SDK result is:$result"); } + Future initClickstreamWithoutGlobalAttribute() async { + bool result = await analytics.init( + appId: "shopping", + endpoint: testEndpoint, + isLogEvents: true, + isTrackScreenViewEvents: true, + isCompressEvents: false, + sessionTimeoutDuration: 30000, + ); + log("init SDK result is:$result"); + } + @override Widget build(BuildContext context) { return MaterialApp( @@ -75,6 +87,14 @@ class _MyAppState extends State { }, minLeadingWidth: 0, ), + ListTile( + leading: const Icon(Icons.not_started_sharp), + title: const Text('initSDKWithoutGlobalAttribute'), + onTap: () async { + initClickstreamWithoutGlobalAttribute(); + }, + minLeadingWidth: 0, + ), ListTile( leading: const Icon(Icons.circle), title: const Text('recordEventWithName'), diff --git a/ios/Classes/ClickstreamFlutterPlugin.swift b/ios/Classes/ClickstreamFlutterPlugin.swift index d408180..853ddf3 100644 --- a/ios/Classes/ClickstreamFlutterPlugin.swift +++ b/ios/Classes/ClickstreamFlutterPlugin.swift @@ -56,8 +56,7 @@ public class ClickstreamFlutterPlugin: NSObject, FlutterPlugin { .withSessionTimeoutDuration(arguments["sessionTimeoutDuration"] as! Int64) .withCompressEvents(arguments["isCompressEvents"] as! Bool) .withAuthCookie(arguments["authCookie"] as! String) - if arguments["globalAttributes"] != nil { - let attributes = arguments["globalAttributes"] as! [String: Any] + if let attributes = arguments["globalAttributes"] as? [String: Any] { if attributes.count > 0 { let globalAttributes = getClickstreamAttributes(attributes) _ = configuration.withInitialGlobalAttributes(globalAttributes)