gpt4 book ai didi

iphone - 当 iPhone 应用程序在后台运行时显示弹出窗口 (UIAlertView)

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:03:56 25 4
gpt4 key购买 nike

我是 iPhone 应用程序开发的新手。

我的问题是当我的应用程序在后台运行时如何显示弹出窗口 (UIAlertView)?我正在为 ios 6 使用 xcode 4.2我无法在互联网上找到满意的答案。有人可以帮我解决这个问题吗?

    - (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSTimer* t = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(doBackgroundProcessing) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:t forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
});

    - (void) doBackgroundProcessing
{
global = [lMGlobal getInstance];

while(TRUE)
{
[self showAlertFor:@"Hello" andMessage:@"Wake up"];

[NSThread sleepUntilDate:[lMGlobal getSleepDuration]];

}

}

- (void) showAlertFor:(NSString *)title andMessage:(NSString*)message
{
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:title
message:message
delegate: self
cancelButtonTitle: nil
otherButtonTitles: @"Mute", nil];

[alertDialog
performSelector:@selector(show)
onThread:[NSThread mainThread]
withObject:nil
waitUntilDone:NO];
[alertDialog release];
}

最佳答案

虽然您不能显示 UIAlertView,但您可以显示 UILocalNotification。您的代码可能如下所示:

backupAlarm = [[UILocalNotification alloc] init];

backupAlarm.fireDate = alarmTime;
backupAlarm.timeZone = [NSTimeZone systemTimeZone];

backupAlarm.alertBody = @"Good morning, time to wake up.";
backupAlarm.alertAction = @"Show me";
backupAlarm.soundName = UILocalNotificationDefaultSoundName;

关于iphone - 当 iPhone 应用程序在后台运行时显示弹出窗口 (UIAlertView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13620284/

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