Skip to content

Commit 3533b18

Browse files
committed
fix/Fix for fetch recommendations crash
1 parent 16b567f commit 3533b18

File tree

6 files changed

+42
-16
lines changed

6 files changed

+42
-16
lines changed

example/XamarinExample.Android/MainActivity.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using Android.Runtime;
66
using Android.OS;
77
using Android.Content;
8-
using Android.Widget;
9-
using ExponeaSdk;
108

119
namespace XamarinExample.Droid
1210
{

example/XamarinExample/ConfigInfoPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535

3636
</StackLayout>
3737

38-
<StackLayout Orientation="Horizontal">
38+
<!--<StackLayout Orientation="Horizontal">
3939
4040
<Label Text="Token Tracking Frequency" Margin="0,0,20,0"/>
4141
<Label Text="{Binding TokenTrackFrequency}" TextColor="#005FDB"/>
4242
43-
</StackLayout>
43+
</StackLayout>-->
4444

4545
<Label Text="Default properties"/>
4646
<Label x:Name="defaultProperties" TextColor="#005FDB"/>

example/XamarinExample/MainPage.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ async void Switch_Project_ClickedAsync(System.Object sender, System.EventArgs e)
116116

117117
_exponea.SwitchProject(new Project(projectToken, authorization, baseUrl));
118118
customerCookie.Text = "Customer cookie: \n" + _exponea.CustomerCookie;
119+
Preferences.Set("projectToken", projectToken);
120+
Preferences.Set("authorization", authorization);
121+
Preferences.Set("baseURL", baseUrl);
119122
}
120123

121124
async void Show_Configuration_ClickedAsync(System.Object sender, System.EventArgs e)
@@ -131,7 +134,6 @@ void Track_Session_Start_Clicked(System.Object sender, System.EventArgs e)
131134
void Track_Session_End_Clicked(System.Object sender, System.EventArgs e)
132135
{
133136
_exponea.TrackSessionEnd();
134-
_exponea.TrackPushToken("token");
135137
}
136138
}
137139
}

pcl/RecommendationsRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public RecommendationsRequest(string id, bool fillWithRandom = false, int size =
2020
public int Size { get; set; } = DefaultSize;
2121
public IDictionary<string, string> Items { get; set; } = new Dictionary<string, string>();
2222
public bool NoTrack { get; set; }
23-
public IList<string> CatalogAttributesWhitelist { get; set; } = new List<string>();
23+
public List<string> CatalogAttributesWhitelist { get; set; } = new List<string>();
2424
}
2525
}

pcl/iOS/ConversionExtensions.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ public static NSMutableDictionary<NSString, NSObject> ToNsDictionary<TValue>(thi
2424
return res;
2525
}
2626

27+
public static NSArray ToNSArray<TValue>(this List<TValue> list)
28+
{
29+
30+
if (list == null)
31+
{
32+
return null;
33+
}
34+
35+
var array = new NSObject[list.Count];
36+
37+
for (int i = 0; i < list.Count; i++)
38+
{
39+
array[i] = list[i].ToNSObject();
40+
}
41+
42+
return NSArray.FromNSObjects<NSObject>(array);
43+
}
44+
2745
public static NSMutableDictionary<NSString, NSMutableArray> ToNsDictionary(this IDictionary<EventType, IList<Project>> dic)
2846
{
2947
if (dic == null)
@@ -142,8 +160,9 @@ public static NSObject ToNSObject(this object value)
142160
float f => new NSNumber(f),
143161
double d => new NSNumber(d),
144162
string s => new NSString(s),
163+
bool b => new NSNumber(b),
145164
NSObject o => o,
146-
_ => throw new NotSupportedException()
165+
_ => throw new ArgumentException()
147166
};
148167
}
149168
}

pcl/iOS/ExponeaSdk.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,24 @@ public Task<string> FetchRecommendationsAsync(RecommendationsRequest request)
7979
var tcs = new TaskCompletionSource<string>();
8080

8181
var options = new NSDictionary(
82-
"id", request.Id,
83-
"fillWithRandom", request.FillWithRandom,
84-
"size", request.Size,
82+
"id", request.Id.ToNSObject(),
83+
"fillWithRandom", request.FillWithRandom.ToNSObject(),
84+
"size", request.Size.ToNSObject(),
8585
"items", request.Items.ToNsDictionary<string>(),
86-
"noTrack", request.NoTrack,
87-
"catalogAttributesWhitelist", request.CatalogAttributesWhitelist);
86+
"noTrack", request.NoTrack.ToNSObject(),
87+
"catalogAttributesWhitelist", request.CatalogAttributesWhitelist.ToNSArray<string>());
88+
89+
Action<NSString> successDelegate = delegate (NSString success) {
90+
//TODO: Parse result as list of CustomerRecommendation
91+
tcs.SetResult(success);
92+
};
93+
94+
Action<NSString> failDelegate = delegate (NSString error) {
95+
tcs.SetException(new FetchException(error, error));
96+
};
97+
98+
_exponea.FetchRecommendations(options, successDelegate, failDelegate);
8899

89-
_exponea.FetchRecommendations(
90-
options,
91-
success => tcs.SetResult(success), //TODO: Parse result as list of CustomerRecommendation
92-
failure => tcs.SetException(new FetchException(failure, failure)));
93100
return tcs.Task;
94101
}
95102

0 commit comments

Comments
 (0)