Created
April 20, 2015 22:17
-
-
Save agathe/de760f79ce666d9690fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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