首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >推送通知后运行函数

推送通知后运行函数
EN

Stack Overflow用户
提问于 2013-03-24 20:26:20
回答 1查看 617关注 0票数 3

我正在为iPad开发一个iOS应用程序。我正在通过一个名为HelpShift的服务使用推送通知。我想在用户点击通知时运行一段代码。当应用程序处于活动状态时,它实际上可以工作,但当它处于后台或非活动状态时,它就不能工作了。下面是我的代码:

代码语言:javascript
复制
- (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];}
 }

所以正如你所看到的,问题是self showHelpShift没有被调用或者它被提前调用。

EN

回答 1

Stack Overflow用户

发布于 2013-03-24 20:30:00

实现application:didFinishLaunchingWithOptions:并在launchOptions字典中查找UIApplicationLaunchOptionsRemoteNotificationKey密钥。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15598433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档