This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
PlayFabLocalizationAPI.m
79 lines (63 loc) · 2.99 KB
/
PlayFabLocalizationAPI.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#import "PlayFabLocalizationAPI.h"
#import "PlayFabConnection.h"
#import <UIKit/UIKit.h>
#include <sys/sysctl.h>
#import "JAGPropertyConverter.h"
@implementation PlayFabLocalizationAPI
+(NSString*) GetURL {
return [NSString stringWithFormat:@"https://%@%@", [PlayFabSettings.VerticalName length] != 0 ? PlayFabSettings.VerticalName : PlayFabSettings.TitleId, PlayFabSettings.ProductionEnvironmentURL];
}
static PlayFabClientAPI* PlayFabInstance;
+ (PlayFabClientAPI*) GetInstance {
if(PlayFabInstance == NULL) {
PlayFabInstance = [PlayFabClientAPI new];
}
return PlayFabInstance;
}
+ (NSString *)getModel {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *model = malloc(size);
sysctlbyname("hw.machine", model, &size, NULL, 0);
NSString *deviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
free(model);
return deviceModel;
}
-(void) GetLanguageList:(LocalizationGetLanguageListRequest*)request success:(GetLanguageListCallback)callback failure:(ErrorCallback)errorCallback withUserData:(NSObject*)userData
{
NSString *jsonString = [request JSONStringWithClass:[LocalizationGetLanguageListRequest class]];
PlayFabConnection * connection = [PlayFabConnection new];//[[MyConnection alloc]initWithRequest:req];
[connection setCompletionBlock:^(id obj, NSError *err) {
NSData * data = obj;
if (!err) {
//NSLog(@"connection success response: %@",(NSString*)data);
NSError *e = nil;
NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:data options:0 error: &e];
NSString* playfab_error = [JSON valueForKey:@"error"];
if (playfab_error != nil) {
//if there was an "error" object in the JSON:
PlayFabError *playfab_error_object = [[PlayFabError new] initWithDictionary:JSON];
errorCallback (playfab_error_object, userData);
} else {
NSDictionary *class_data = [JSON valueForKey:@"data"];
LocalizationGetLanguageListResponse *model = [[LocalizationGetLanguageListResponse new] initWithDictionary:class_data];
callback (model, userData);
}
} else { //Connection Error:
NSError *e = nil;
NSLog(@"connection error response: %@",data);
PlayFabError *model;
if (data != nil) {
NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &e];
JAGPropertyConverter *converter = [JAGPropertyConverter new];
model = [converter composeModelFromObject:JSON];
} else {
model = [PlayFabError new];
model.error = @"unknown, data empty.";
}
errorCallback (model, userData);
}
}];
[connection postURL:[NSString stringWithFormat:@"%@%@",[PlayFabClientAPI GetURL],@"/Locale/GetLanguageList"] body:jsonString authType:nil authKey:nil];
}
@end