首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在iPhone SDK中后台告警?

如何在iPhone SDK中后台告警?
EN

Stack Overflow用户
提问于 2012-07-31 12:24:19
回答 2查看 1.9K关注 0票数 2

我将闹钟时间设置为1小时。当应用程序处于运行模式时,警报工作正常,但当它在后台时,警报不能正常工作。如何在后台运行警报?

EN

回答 2

Stack Overflow用户

发布于 2012-07-31 12:28:44

您需要使用本地通知。这很简单。更多信息请参见本文档(推送通知来自远程来源,您可以忽略它们)。

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1

票数 2
EN

Stack Overflow用户

发布于 2012-07-31 12:56:07

这段代码只是在背景中显示带有警告和声音的localNotification。因此,在警报应用程序中对代码和使用进行了一些更改。

代码语言:javascript
复制
- (IBAction)Alert:(id)sender{

    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:@"yyyy-MM-dd"];
    //NSDate *date = [NSDate date];


    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    localNotif.fireDate =[NSDate dateWithTimeIntervalSinceNow:15];
    localNotif.timeZone = [NSTimeZone localTimeZone];
    localNotif.alertBody = @"Emergency";

    localNotif.alertAction = @"View";
    localNotif.soundName = @"police.mp3";
    localNotif.applicationIconBadgeNumber = 1;
    localNotif.repeatInterval = NSYearCalendarUnit;


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



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

https://stackoverflow.com/questions/11733069

复制
相关文章

相似问题

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