Pergunta

Ready to make a fool out of myself:

I have this skeleton app, that has the PushWoosh notification classes in place. It works fine. I'm able to send a push message to my app.

For this to work, in my AppDelegate, there is a method called

- (void) onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification

that allows me to fire off stuff when a notification is accepted.

Meanwhile, in my ViewController, I have a method like this:

-(void)loadURL{
    NSLog(@"testing");
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:TOPIC]]];
    [webView reload];
}

This one works fine when called from the ViewController itself.

However, when I try to call this method from within the 'onPushAccepted' method in the appDelegate, the webView does not show the desired URL, although, as indicated by the logging, the method IS called.

I guess this shows that I'm lacking some fundamental understanding of the working of this all.

Therefore, I would be satisfied with some some strings that would make this work, but I would be really happy with an explanation on the why and how behind it.

I tried putting the onPushAccepted: in the ViewController, but that didn't work at all, although I included the necessary "PushNotificationManager.h" in the ViewController.m.

I'm confused, and need your help.

I think your answer will get me close to getting the basics.

Thanks ahead!

Foi útil?

Solução

In this specific case Sjakelien was using a Single View Application. The confusion was that the attempt to instantiate the ViewController in AppDelegate by doing the following ViewController * vc = [[ViewController alloc]init]; [vc loadURL]; did not work.

In this case the solution is the get the ViewController that is displayed on screen by using

- (void) onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification {
  ViewController *vc = (ViewController*)self.window.rootViewController;
  [vc loadURL];
}

Applications with a different setup such as a UINavigationController need to take different actions.

A few choices:

  • popToRootViewController and instantiate a new instance of ViewController and push it onto the navigation stack

  • Push a new instance of ViewController onto the navigation stack without using popToRootViewController

  • Present the ViewController in a modal
  • Modify the model of the application
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top