【问题标题】:background application for iphone 4iphone 4的后台应用
【发布时间】:2011-04-09 15:53:35
【问题描述】:


我想让我的应用每 20 分钟播放一次声音,即使应用处于后台或 iphone 处于睡眠模式...我使用:[NSTimer scheduledTimerWithTimeInterval:delay*60.0 target:self 选择器:@选择器(goMethod)用户信息:无重复:是];可能工作 1 小时然后停止,任何人都可以帮我解决这个问题...

【问题讨论】:

    标签: iphone xcode audio background


    【解决方案1】:

    使用 UILocalNotifications。

    3 个通知(即 13:00、13:20 和 13:40)与 repeatinterval:NSHourCalendarUnit..

    编辑: 像这样的:

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.soundName = UILocalNotificationDefaultSoundName;
        localNotif.repeatInterval = NSHourCalendarUnit; //Repeat every hour
    
    localNotif.fireDate = [NSDate date]; //Now
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    
    localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:1200]; //Now + 20 min
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    
    localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:2400]; //Now + 40 min
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    
    [localNotif release];
    

    【讨论】:

    • txt 用于回复,但我不会是通知(通知是带有按钮的警报)...我必须播放短声(1.0 秒或更短)并计算这个声音的数量没有让用户点击通知按钮,所以如果你能帮助我任何想法,我将不胜感激
    • 我相信通知可以是:带有按钮或声音或徽章或这些的任何组合的警报。我建议使用只有声音的 UILocalNotifications!这也是我能想到的唯一方法..
    • txt 再次重播我尝试它并且它正在工作但在我的重播中我说我需要计算这个声音正在播放多少(通过这个计数我将更改声音和 timerInterval 示例:如果计数为 4 我将每 20 分钟播放一次 do.aiff 如果计数为 60 我将每 35 分钟播放一次 re.aiff 如果计数为 120 我将播放 mi.aiff 5 分钟等...)所以我现在的问题我如何才能捕捉到播放了多少声音...再次为您的帮助 txt
    • 嗯,基本上你不能......你必须启动一条消息,用户必须输入你的应用程序。您唯一能做的就是弄清楚何时播放所有声音并添加通知..您可能不需要计算是吗?你知道声音什么时候播放。所以弄清楚计数和何时安排什么声音是简单的数学..
    • 嗨,我想在我的应用程序中更改一些内容...我希望通知每 2 小时重复一次,所以请您修改此代码:localNotif.repeatInterval = NSHourCalendarUnit; //每小时重复一次,我想从晚上 11 点到早上 7 点停止通知,谁能帮助我,我将不胜感激
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 2023-03-20
    相关资源
    最近更新 更多