gpt4 book ai didi

iphone - iOS 如何告诉 App Delegate 从当前 View 呈现新 View

转载 作者:行者123 更新时间:2023-12-01 16:50:29 27 4
gpt4 key购买 nike

我有一个 iPhone 应用程序,当用户当前未使用该应用程序时,它会接收通知。当用户单击通知时,由于打开通知而打开应用程序时,他们应该被带到一个新 View 。

我将用于从通知传递我的信息的 App Delegate 中的委托(delegate)方法是:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

//Pass my data from JSON Payload in here

//Tell current view to go to new view

}

我相信对用户在退出应用程序之前与之交互的最后一个 View Controller 的引用将是一种解决方法并将对象存储在 NSUserDefaults 中。 .

任何关于我如何实现这一点的建议将不胜感激。

最佳答案

尝试使用 NSNotificationCenter :) 在应该完成推送的位置注册一个观察者,并从您的 appdelegate 发出通知。看看这个tutorial用于注册和射击;)

// AppDelegate
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

//Pass my data from JSON Payload in here
NSObject *obj = myInformationForTheReciever;
[[NSNotificationCenter defaultCenter] postNotificationName:@"goToView" object:obj];
}

-
// MyViewController
-(void)viewDidLoad
{
[super viewDidLoad];
// do your stuff

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToView:) name:@"goToView" object:nil];
}

- (void)goToView:(NSNotification*)notification
{
NSObject* myInformationForTheReciever = [notification object];
// do stuff with that
}

关于iphone - iOS 如何告诉 App Delegate 从当前 View 呈现新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16443058/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com