Skip to content

Instantly share code, notes, and snippets.

@agathe
Created April 20, 2015 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agathe/de760f79ce666d9690fa to your computer and use it in GitHub Desktop.
Save agathe/de760f79ce666d9690fa to your computer and use it in GitHub Desktop.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
@weakify(self);
DDLogDebug(@"application:didReceiveRemoteNotification:fetchCompletionHandler: %@", userInfo);
if (userInfo[@"layer"]){
[[[[CAPUserController sharedUserController] layerClient]
rac_synchronizeWithRemoteNotification:userInfo]
subscribeNext:^(LYRMessage *message) {
if (message){
NSString *alertString = userInfo[@"aps"][@"alert"];
// get only the NSData from the part that is downloaded completely
NSArray *imageParts = [[message.parts.rac_sequence filter:^BOOL(LYRMessagePart *part) {
DDLogVerbose(@"part %@", part);
return part.transferStatus == LYRContentTransferComplete &&
([part.MIMEType containsString:@"image"]
|| [part.MIMEType containsString:@"png"]);
}] array];
LYRMessagePart *part = imageParts.firstObject;
NSData *data = part.data; // date is not nil
if (application.applicationState == UIApplicationStateInactive
|| application.applicationState == UIApplicationStateActive) {
if (data.length > 0){
UIImage *im = [UIImage imageWithData:data];
CGSize size = im.size;
DDLogVerbose(@"metadata %@", NSStringFromCGSize(size));
if (size.width == 201 && size.height == 202){
dispatch_async(dispatch_get_main_queue(), ^{
// TODO custom alertview that shows the image and yes/no buttons
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Image"
message:alertString
delegate:nil
cancelButtonTitle:@"YesNo"
otherButtonTitles:nil];
[alertView show];
});
}
}
if (alertString.length > 0) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Message"
message:alertString
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
});
}
}
completionHandler(UIBackgroundFetchResultNewData);
} else {
completionHandler(UIBackgroundFetchResultNoData);
}
}];
} else {
[PFPush handlePush:userInfo];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment