iphone - iOS 通知到达时推送特定 View

标签 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];

}

我可以在这里实现什么来在应用程序到达时推送特定 View (例如,当用户在 iPhone 锁定时滑动应用程序图标时)......我正在尝试 [self.navigationController pushViewController: CompletedViewController animated:YES]; 并且出现一些错误...我应该采用特定的方法吗?也许在 didFinishLaunchingWithOptions 中?

最佳答案

也许你应该这样称呼

[_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];

如果您使用 Storyboard,这就是您从 AppDelegate 推送到当前导航 Controller 的方式。特别是当 Storyboard上的起点是导航 Controller 时。

关于iphone - iOS 通知到达时推送特定 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11203336/

相关文章:

ios - 我可以继承 UIWebView 吗?

ios - 子类化 MKOverlayPathView 以创建 MKPolylineView

ios - block 执行iOS并分配变量

iOS应用商店应用名称通过testflight beta应用预留

ios - 为什么我会收到以下错误 : "fatal error: unexpectedly found nil while unwrapping an Optional value"? - 如何具体修复它?

iphone - 自定义 UITableViewCell 编辑AccessoryView?

ios - ios编程中如何使用Keychain

iphone - performFetchWithCompletionHandler 只会被调用

iOS UITableView : changing background color of table overrides background color of cells

ios - xcode:添加约束后标签不显示