首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当iPhone应用程序在后台运行时显示弹出窗口(UIAlertView

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

Stack Overflow用户
提问于 2012-11-29 14:46:50
回答 4查看 5.2K关注 0票数 2

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

我的问题是,当我的应用程序在后台运行时,我如何显示弹出窗口(UIAlertView)?我正在使用iOS6的xcode 4.2,我无法在互联网上找到满意的答案。有没有人能帮我一下?

代码语言:javascript
复制
    - (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];
    });

}

代码语言:javascript
复制
    - (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];
      }
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-11-29 14:55:02

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

代码语言:javascript
复制
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;
票数 8
EN

Stack Overflow用户

发布于 2012-11-29 14:48:42

不可能让你的应用程序在后台运行时显示UIAlertView

票数 0
EN

Stack Overflow用户

发布于 2012-11-29 14:54:22

我认为你不能直接这么做,但你可以 UILocalNotification!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13620284

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档