Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit 3ce3871

Browse files
committed
0.3.4: Login works again!
1 parent 10996c2 commit 3ce3871

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

Pod/Classes/Categories/NSString+SnapchatKit.m

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ + (NSString *)queryStringWithParams:(NSDictionary *)params URLEscapeValues:(BOOL
116116
if (params.allKeys.count == 0) return @"";
117117

118118
NSMutableString *q = [NSMutableString string];
119-
[params enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
119+
[params enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
120120
if ([value isKindOfClass:[NSString class]]) {
121121
if (escapeValues) {
122-
value = [(NSString *)value urlencode];
122+
value = [value URLEncodedString];
123123
} else {
124-
value = [(NSString *)value stringByReplacingOccurrencesOfString:@" " withString:@"+"];
124+
value = [value stringByReplacingOccurrencesOfString:@" " withString:@"+"];
125125
}
126126
}
127127
[q appendFormat:@"%@=%@&", key, value];
@@ -132,24 +132,26 @@ + (NSString *)queryStringWithParams:(NSDictionary *)params URLEscapeValues:(BOOL
132132
return q;
133133
}
134134

135-
- (NSString *)urlencode {
136-
NSMutableString *output = [NSMutableString string];
137-
const unsigned char *source = (const unsigned char *)[self UTF8String];
138-
int sourceLen = (int)strlen((const char *)source);
139-
for (int i = 0; i < sourceLen; ++i) {
140-
const unsigned char thisChar = source[i];
141-
if (thisChar == ' '){
142-
[output appendString:@"+"];
143-
} else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
144-
(thisChar >= 'a' && thisChar <= 'z') ||
145-
(thisChar >= 'A' && thisChar <= 'Z') ||
146-
(thisChar >= '0' && thisChar <= '9')) {
147-
[output appendFormat:@"%c", thisChar];
135+
- (NSString *)URLEncodedString {
136+
NSMutableString *encoded = [NSMutableString string];
137+
const unsigned char *source = (const unsigned char *)self.UTF8String;
138+
NSInteger sourceLen = (NSInteger)strlen((const char *)source);
139+
140+
for (NSInteger i = 0; i < sourceLen; i++) {
141+
const unsigned char c = source[i];
142+
if (c == ' '){
143+
[encoded appendString:@"+"];
144+
} else if (c == '.' || c == '-' || c == '_' || c == '~' ||
145+
(c >= 'a' && c <= 'z') ||
146+
(c >= 'A' && c <= 'Z') ||
147+
(c >= '0' && c <= '9')) {
148+
[encoded appendFormat:@"%c", c];
148149
} else {
149-
[output appendFormat:@"%%%02X", thisChar];
150+
[encoded appendFormat:@"%%%02X", c];
150151
}
151152
}
152-
return output;
153+
154+
return encoded;
153155
}
154156

155157
@end

Pod/Classes/Networking/SKClient.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,11 @@ - (void)getAttestation:(NSString *)username password:(NSString *)password ts:(NS
337337
NSDictionary *query = @{@"bytecode_proto": bytecodeProtobuf,
338338
@"nonce": hashString,
339339
@"apk_digest": SKAttestation.digest9_14_2};
340-
341340
request.URL = [NSURL URLWithString:SKAttestation.protobufPOSTURL];
342-
request.HTTPBody = [[NSString queryStringWithParamsForAttestion:query] dataUsingEncoding:NSUTF8StringEncoding];
343-
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
341+
request.HTTPBody = [[NSString queryStringWithParams:query URLEscapeValues:YES] dataUsingEncoding:NSUTF8StringEncoding];
342+
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:SKHeaders.contentType];
344343

345344
[[session dataTaskWithRequest:request completionHandler:^(NSData *data2, NSURLResponse *response2, NSError *error2) {
346-
347345
if (!error2 && [(NSHTTPURLResponse *)response2 statusCode] == 200) {
348346
jsonError = nil;
349347
json = [NSJSONSerialization JSONObjectWithData:data2 options:0 error:&jsonError];
@@ -361,7 +359,10 @@ - (void)getAttestation:(NSString *)username password:(NSString *)password ts:(NS
361359
if (!error3 && [(NSHTTPURLResponse *)response3 statusCode] == 200) {
362360
jsonError = nil;
363361
json = [NSJSONSerialization JSONObjectWithData:data3 options:0 error:&jsonError];
364-
callback(json[@"signedAttestation"], nil);
362+
if (json)
363+
callback(json[@"signedAttestation"], nil);
364+
else
365+
callback(nil, jsonError);
365366
} else {
366367
callback(nil, error3);
367368
}
@@ -371,7 +372,6 @@ - (void)getAttestation:(NSString *)username password:(NSString *)password ts:(NS
371372
callback(nil, jsonError);
372373
}
373374
} else {
374-
// Error: 400, bad request (missing parameter according to Liam)
375375
callback(nil, error2);
376376
}
377377
}] resume];

SnapchatKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "SnapchatKit"
3-
s.version = "0.3.3"
3+
s.version = "0.3.4"
44
s.summary = "An Objective-C implementation of the unofficial Snapchat API."
55
s.homepage = "https://github.com/ThePantsThief/SnapchatKit"
66
s.license = 'MIT'

0 commit comments

Comments
 (0)