简体   繁体   English

当应用未处于运行状态iOS时通过通知横幅打开应用

[英]Open app through notification banner when app is not running state iOS

I have tabbar controller having three tab, attached three navigation controller I want to go to second controller of navigation controller just like whatsapp. 我有三个标签的选项卡控制器,附加了三个导航控制器,我想像whatsapp一样转到导航控制器的第二个控制器。 I handled successfully for background state, but for not running state. 我成功处理了后台状态,但没有运行状态。 Below is my code in didfinishlaunch delegate method of uiapplication. 下面是我在uiapplication的didfinishlaunch委托方法中的代码。

if (launchOptions != nil) {
        // Launched from push notification

        NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];


        [self performSelector:@selector(notificationObserverAfterDelay:) withObject:notification afterDelay:2.0];

    }

-(void)notificationObserverAfterDelay:(NSDictionary *)userInfo
{
  [[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshUIChatNotRunningState" object:self userInfo:userInfo];
}

Nazish Ali, 纳兹什·阿里,

Sending out notification after delay of 2 seconds is really not a good idea. 延迟2秒后发送通知确实不是一个好主意。

Declare a method which accepts your userInfo dictionary as argument in your viewController having tab bar. 声明一个方法,该方法接受带标签栏的viewController中的userInfo字典作为参数。

lets call it as, 让我们称之为

YourViewController.h YourViewController.h

-(void)appStartedFromPushNotification : (NSDictionary *)userInfo;

YourViewController.m YourViewController.m

-(void)appStartedFromPushNotification : (NSDictionary *)userInfo {
       //now the control has reached yourViewController with tab bar
       //change the tab bar selection and perform segue and load the next viewController and use prepareforSgue to pass the data
}

Now why YourViewController only why not the actualViewController which anyway needs to be loaded ??? 现在,为什么要使用YourViewController而不是为什么不必须要加载的actualViewController? Reason you dont want mess with navigation stack manually. 您不希望手动弄乱导航堆栈的原因。 Because YourViewController is the child of UINavigationController and UINavigationController is your rootView controller YourViewController will be loaded automatically. 由于YourViewController是UINavigationController的子级,而UINavigationController是您的rootView控制器,因此YourViewController将自动加载。 So just access it and ask it to perform the tab change and load viewControllers so your navigation stack will continue to be stable :) 因此,只需访问它并要求它执行选项卡更改并加载viewControllers,以便您的导航堆栈将继续保持稳定:)

finally in Appdelegate, 终于在Appdelegate中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 NSDictionary *userInfo = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if (launchOptions) {
        [self handleReceiveRemoteNotification: userInfo];
    }
    return YES;
}

Declare a method in AppDelegate.m and access the YourViewController instance and handover data to it thats all :) 在AppDelegate.m中声明一个方法,然后访问YourViewController实例并将数据移交给这一切:)

- (void) handleReceiveRemoteNotification:(NSDictionary *)userInfo{
    UINavigationController *rootViewController = (UINavigationController *)self.window.rootViewController;
    for(UIViewController *viewController in rootViewController.viewControllers){

        if([viewController isKindOfClass:[YourViewController class]]) {
                [viewController appStartedFromPushNotification:userInfo];
        }
}

That should do the job :) Happy coding :) 那应该做的工作:)快乐编码:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当您的应用程序打开并处于前台时显示股票 iOS 通知横幅? - Displaying a stock iOS notification banner when your app is open and in the foreground? 处于“未运行”状态时在iOS应用中推送通知 - Push notification in iOS app when “Not running” state 通过“推送通知”从“终止”状态打开应用程序时,iOS Web View App崩溃 - iOS Web View App crashed when Application is open from kill state through Push Notification 通过推送通知Objective C iOS从“终止”状态打开时,应用崩溃 - App crash when open from Kill state through Push notification Objective C iOS 当应用程序在 iOS 中处于运行状态时检测推送通知选择 - Detect push notification selection when the app is at running state in iOS flutter 通知不会出现在 ios 当应用程序正在杀死 state 但当我们打开应用程序时通知即将到来 - flutter notification is not coming in ios when app is on kill state but when we open the app notification is coming 当应用程序处于焦点状态时,无法将OneSignal通知显示为横幅:iOS - Not able to display OneSignal notification as a Banner when the App is in focus :iOS iOS推送通知-检查应用程序在后台时横幅是否显示 - iOS Push Notification - check if the banner is showing when app is in background 当我收到静默推送通知时,iOS 会唤醒我的应用程序吗?(当应用程序未处于运行状态时) - Will iOS awake my app when i receive silent push notification?(When app is not in running state) 确定在应用程序处于后台状态时是否轻按了中心的通知横幅或通知以启动应用程序 - Determine if notification banner or notification in center was tapped to launch the app when app is background state
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM