I'm developing an iOS app for iPad. I'm using Push notifications with a service called HelpShift. I'd like to run a piece of code when the users taps the notification. It actually works when the app is active, but when it's background or inactive, it doesn't work. Here is my code:
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if ([[userInfo objectForKey:@"origin"] isEqualToString:@"helpshift"]) {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"You were answered in HelpShift"
message:@"Hello"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Show", nil];
[alertView show];
} if (state== UIApplicationStateBackground) {
UIViewController *vc = self.window.rootViewController;
[[Helpshift sharedInstance] handleNotification:userInfo withController:vc];
[self showHelpShift];
} if (state == UIApplicationStateInactive) {
UIViewController *viewController =
[[UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:NULL] instantiateViewControllerWithIdentifier:@"home"];
[[Helpshift sharedInstance] handleNotification:userInfo withController:viewController];
}
}
}
- (void) showHelpShift {
UIViewController *vc = self.window.rootViewController;
[[Helpshift sharedInstance] showSupport:vc];
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1){
UIViewController *vc = self.window.rootViewController;
[[Helpshift sharedInstance] showSupport:vc];}
}
So as you can see, the problem is that the [self showHelpShift] doesn't get called or it gets called to early.