轻触的appDelegate事件(Touch events in appDelegate)

2019-10-18 01:21发布

Here's my problem.

I have implemented push notification in my app and it works just fine.

  • The app receives a message
  • Captured in appDelegates: didReceiveRemoteNotification
  • Creates a new UIView to display that a new message is received

Only problem I have is that I want the user to be able to tap on the message so that the app will open the message viewcontroller. But I can't seem to figure out how to capture this touch and then do something with it in the appDelegate. I have an NSLog in the method that should open the new viewcontroller but it seems that it is never called.

Any help would be appreciated!

Here's the code, it is in the didReceiveRemoteNotification method:

    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoMessages)];
    UIView *messageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
    messageView.userInteractionEnabled = YES;
    messageView.backgroundColor = [UIColor darkGrayColor];
    [messageView addGestureRecognizer:recognizer];
    [self.window addSubview:messageView];

Thanks!

Answer 1:

我建议您不要使用您的应用程序委托类此。 这不是什么它是,它会导致混乱的设计。

你为什么不使用常规视图控制器和UIView子类? 他们是手势和触摸输入的天然场所。

至于为什么你的NSLog没有出现,这可能有助于证明代码。

您双击手势识别器似乎配置为允许任何轻点屏幕上的任何地方,而不是攻权上的消息,你提到。 仅供参考。



文章来源: Touch events in appDelegate