iOS在通知到达时推送特定视图

时间:2012-06-26 08:20:11

标签: iphone ios xcode uilocalnotification pushviewcontroller

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    // Handle the notificaton when the app is running

    NSLog(@"Recieved Notification %@",notif);

    NSLog(@"local notifications count = %d", [[[UIApplication sharedApplication] scheduledLocalNotifications] count]);


    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"everything9", CFSTR ("mp3"), NULL);
    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);



    [[NSNotificationCenter defaultCenter] postNotificationName:@"RELOAD_DATA"object:nil];

}

我可以在这里实现什么来在应用程序到达时推送特定视图(例如,当iPhone被锁定时用户滑动应用程序图标)...我正在尝试[self.navigationController pushViewController:CompletedViewController animated:YES];我得到一些错误......我应该采取哪种具体方式吗?也许在didFinishLaunchingWithOptions

5 个答案:

答案 0 :(得分:3)

也许你应该叫这个

[_ window.rootViewController pushViewController:CompletedViewController animated:YES];

上面的代码现在不起作用。你应该尝试使用它。

 //We take the rootViewController first which is expected to be a UINavigationController in your case
 UINavigationController *naviController = _window.rootViewController;  
 //We then call the push view controller code    
 [naviController pushViewController:CompletedViewController animated:YES];

如果您使用的是故事板,这就是您从AppDelegate推送到当前导航控制器的方式。特别是如果故事板上的起点是导航控制器。

答案 1 :(得分:0)

我认为this符合您的需求。它将教授如何在UINavigationController内使用AppDelegate。如果您有其他问题,请告诉我。

答案 2 :(得分:0)

在Xcode的旧版本中,我们在创建应用程序时有一个选项是基于导航的应用程序。但在最新的Xcode代中,我们可以创建基于单视图或基于窗口的应用程序。因此,如果要使用导航控制器属性,则需要为UINavigationController创建实例,并需要设置rootViewController。代码如下,

appDelegate.h

@property (strong, nonatomic) UINavigationController *navigationController;

appDelegate.m

@implementation AppDelegate
@synthesize navigationController = _navigationController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

这样,您可以在整个应用程序中使用导航属性。

我认为这对你有帮助。

答案 3 :(得分:0)

“[self.navigationController pushViewController:viewController animated:YES];”

这不能在AppDelegate.m中使用(即来自didReceiveLocalNotification)。

使用didReceiveLocalNotification中的“self.pushViewController”尝试一次。

答案 4 :(得分:0)

if ([EntNotStrApp isEqualToString:@"1"])
{
    EntNotStrApp=@"0";

    UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];

    UINavigationController *navController = (UINavigationController *)window.rootViewController;

    DumpFeed *dump = [storyboard instantiateViewControllerWithIdentifier:@"DumpFeed"];

    dump.isPushed=YES;

    dump.strUserId = appDelegate.strFriendid;


    [navController pushViewController:dump animated:YES];

}else
{
     [[iToast makeText:NotMess] show];
}