当应用程序在后台时在屏幕上显示警报 [英] Show alert on screen when app is in background

查看:66
本文介绍了当应用程序在后台时在屏幕上显示警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在应用程序处于后台运行一段时间后显示多个警报.

I want to show multiple alerts after some time interval when the app is in background.

当前,我正在使用本地通知来显示警报,但是当用户按下本地通知的取消按钮时,我无法检测到动作.

Currently I am using local notification to show the alert but I cannot detect action when user presses the cancel button of local notification.

 UILocalNotification *localNotif = [[UILocalNotification alloc] init];

            if (localNotif == nil)
                return;
            localNotif.fireDate = [NSDate date];
            localNotif.timeZone = [NSTimeZone defaultTimeZone];

                    // Notification details
                    localNotif.alertBody = @"This is local notification message.";
                    // Set the action button
                    localNotif.alertAction = @"View";
                    localNotif.alertAction = @"Yes";

            localNotif.soundName = UILocalNotificationDefaultSoundName;

            [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
            [localNotif release];

还有其他方法可以在应用程序处于后台时在屏幕上显示警报吗?

Is there any other way I can show alert on screen when app is in background ?

推荐答案

您将无法检测到用户是否决定忽略您的 UIAlertView 在后台,您唯一的选择是使用 UILocalNotification .

You will not be able to detect if you user decided to ignore your UILocalNotification. Since you can not show a UIAlertView in the background your only option is to use UILocalNotification.

但是,正如您指出的那样,您无法检测到用户是否单击了取消"按钮,在iOS6和通知中心中也不再存在取消"按钮.仅当用户选择将通知显示为警报时,才会有关闭按钮.仍然无法检测到您的通知已关闭或完全没有视图.

But as you state you can not detect if the user clicked the cancel button, also with iOS6 and the notification center there no longer is a cancel button. Only if user selected to show you notifications as alerts will there be a close button. Still you can not detect that you notification is closed or not views at all.

您唯一的选择是继续向用户发送垃圾邮件,直到打开应用程序为止.但这被认为是糟糕的用户体验,并可能使您的应用受到用户的憎恶.

Your only option is to keep spamming the use with notification until the app is opened. But it is considered bad user experience and could make you app hated by users.

这篇关于当应用程序在后台时在屏幕上显示警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆