从 didReceiveLocalNotification 加载新视图

发布于 2024-12-26 19:52:28 字数 114 浏览 0 评论 0原文

我已经寻找解决方案几个小时了,我的问题非常简单。 我有一个触发的本地通知,我想加载一个新视图,以便在触发通知并且用户单击“查看”按钮时向用户显示。 这可能吗?如果可以,我该怎么做?

提前致谢 :)

Ive been searching for a solution for hours and my question is really simple.
I have a local notification that fires and i want to load a new view to show the user when the notification has been fired and the user have clicked the "view" button.
Is this possible and if so, how do i do it?

Thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凡尘雨 2025-01-02 19:52:28

在您的 appDelegate 中放置以下代码:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notif {
// show your view here!}

当您的应用程序收到本地通知时调用此方法,您还可以在创建通知时使用“notif”对象来存储有用的数据。

如果您有一个视图 MyView 并且它是 xib 文件(例如 MyView.xib,您将主视图设置为 MyView 类),您可以执行类似的操作来加载它

在 MyView.m 添加一个类方法以从 xib 创建新视图:

+ (id) newMyView
{
    UINib *nib = [UINib nibWithNibName:@"MyView" bundle:nil];
    NSArray *nibArray = [nib instantiateWithOwner:self options:nil];
    MyView *me = [nibArray objectAtIndex: 0];
    return me;
}

然后在本地通知回调中,您可以使用以下内容:

MyView *view = [MyView newMyView];
[self.window addSubView:view];

其中 window 是您通常在应用程序委托模板中拥有的属性。

In your appDelegate put this code:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notif {
// show your view here!}

this method is called when your app receive the local notification and you can also use the "notif" object to store useful data when you create the notification.

If you have a view MyView and it's xib file (like MyView.xib where you set the main view as MyView class) you can do something like this to load it

In MyView.m add a class method to create a new view from a xib:

+ (id) newMyView
{
    UINib *nib = [UINib nibWithNibName:@"MyView" bundle:nil];
    NSArray *nibArray = [nib instantiateWithOwner:self options:nil];
    MyView *me = [nibArray objectAtIndex: 0];
    return me;
}

then in the local notification callback you can have something like:

MyView *view = [MyView newMyView];
[self.window addSubView:view];

Where window is the property you normally have in the app delegate template.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文