Skip to content

Commit

Permalink
remove hard coded stuff from push
Browse files Browse the repository at this point in the history
  • Loading branch information
ms1752 committed Sep 2, 2014
1 parent d9655b3 commit a922997
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions ClearBladeAPI/CBPush.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ @implementation CBPush

+(void)addCurrentUserDeviceToken:(NSData *)token withErrorCallback:(CBPushErrorCallback)errorCallback
{
NSDictionary *params = @{@"device-token": [token base64EncodedDataWithOptions:0],
@"type": @"apple",
@"appid": [self getAppId]};
NSString *deviceToken = [token base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSDictionary *params = @{@"device-token": deviceToken,
@"type": @"apple",
@"appid": [self getAppId]};

CBHTTPRequest *apiRequest = [CBHTTPRequest pushRequestWithAction:@"/ids" withMthod:@"POST" withParams:params];

[apiRequest executeWithSuccessCallback:^(CBHTTPRequestResponse *response) {
//noop on success
//noop on success
} withErrorCallback:^(CBHTTPRequestResponse *response, NSError *error) {
if (errorCallback) {
errorCallback(error);
Expand All @@ -46,29 +47,18 @@ +(void)sendPushWithDictionary:(NSDictionary *)dictionary toUsers:(NSArray *)user
}
}];

/*
{
cbids: [cbids..,]
apple-message string,
android-message string,
windows-message string,
delivery-date: int64,
appid:string
}
*/
}

+(NSString *)getAppId
{
return [[NSBundle mainBundle] bundleIdentifier];
}

+(NSDictionary *)parseDictionaryIntoAPSFormat:(NSDictionary *)dict
+(NSString *)parseDictionaryIntoAPSFormat:(NSDictionary *)dict
{
NSMutableDictionary *parsedDict = [[NSMutableDictionary alloc] init];

NSMutableDictionary *parsedDict;

[parsedDict setValue:[[NSMutableDictionary init] alloc] forKey:@"aps"];
[parsedDict setObject:[[NSMutableDictionary alloc] init] forKey:@"aps"];

for(NSString* key in dict){
if ([key isEqualToString:@"alert"] || [key isEqualToString:@"badge"] || [key isEqualToString:@"sound"]) {
Expand All @@ -78,18 +68,12 @@ +(NSDictionary *)parseDictionaryIntoAPSFormat:(NSDictionary *)dict
}
}

return parsedDict;
/*
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
},
"acme1" : "bar",
"acme2" : 42
}
*/
NSLog(@"%@", parsedDict);

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parsedDict options:0 error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

return jsonString;
}

@end

0 comments on commit a922997

Please sign in to comment.