gpt4 book ai didi

ios - 当应用程序处于前台时,UILocalNotification 在通知中心显示警报

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:07 28 4
gpt4 key购买 nike

我正在使用 UILocalNotification 通知用户他们的日程安排。一切正常,但我想知道是否有一种方法可以在应用程序处于前台时在通知中心显示通知警报。

警报不会在正在运行的应用程序主视图上触发。

请帮帮我。

最佳答案

将这段代码放在 didReceiveRemoteNotification 方法中。

UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
{
NSString *cancelTitle = @"OK";
NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Test"
message:message
delegate:self
cancelButtonTitle:cancelTitle
otherButtonTitles:nil, nil];
[alertView show];

} else
{
//Do stuff that you would do if the application was not active
}

关于ios - 当应用程序处于前台时,UILocalNotification 在通知中心显示警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21409989/

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