Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone-在应用程序处于后台时播放警报声_Iphone_Objective C_Background_Alarm - Fatal编程技术网

iPhone-在应用程序处于后台时播放警报声

iPhone-在应用程序处于后台时播放警报声,iphone,objective-c,background,alarm,Iphone,Objective C,Background,Alarm,你知道如何在iPhone睡觉时播放警报声吗, 比如iPhone内置的时钟应用程序 非常重要的编辑: 在iPhone内置的时钟应用程序中 播放报警声时,如果用户将静音开关切换到静音(振动模式), 警报声仍在继续播放 你知道怎么做吗?唯一的方法是使用本地通知或推送通知。两者都允许声音播放30秒设置按钮连接到视图控制器中运行名为scheduleNotification的方法,该方法使用UILocalNotification类安排通知。代码如下所示: (void)scheduleNotification

你知道如何在iPhone睡觉时播放警报声吗, 比如iPhone内置的时钟应用程序

非常重要的编辑:
在iPhone内置的时钟应用程序中
播放报警声时,如果用户将静音开关切换到静音(振动模式),
警报声仍在继续播放


你知道怎么做吗?

唯一的方法是使用
本地通知
推送通知
。两者都允许声音播放30秒

设置按钮连接到视图控制器中运行名为
scheduleNotification
的方法,该方法使用
UILocalNotification
类安排通知。代码如下所示:

(void)scheduleNotification
{
    [reminderText resignFirstResponder];
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil)
    {
        UILocalNotification *notif = [[cls alloc] init];
        notif.fireDate = [datePicker date];
        notif.timeZone = [NSTimeZone defaultTimeZone];
        notif.alertBody = @"Did you forget something?";
        notif.alertAction = @"Show me";
        notif.soundName = UILocalNotificationDefaultSoundName;
        notif.applicationIconBadgeNumber = 1;
        NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text 
              forKey:kRemindMeNotificationDataKey];
        notif.userInfo = userDict;
        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        [notif release];
    }
}

在应用程序进入后台之前,使用AVAudioPlayer播放无声声音,并使其无限次播放。当通知生效时,再次使用AVAudioPlayer播放通知声音,而不是UILocalNotification对象。这对我很有效。

所以看看i-qi应用程序,他们很可能在info.plist中将UIBackgroundModes设置为“音频”。这意味着他们可以在后台播放音频。他们可能会一直播放无声音频,直到计时器结束,因为如果不使用背景音频会话,背景音频会话将被切断

就静音开关而言,这可能是基于他们使用的会话类别。查看此资源:

此代码将帮助您在后台播放音乐: 音乐的声音文件应该只有30秒 通知支持30秒的声音文件,它应该在bundle文件夹中如果它在document文件夹中,那么您必须放置声音文件的路径

NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSString *dateValueRemaining =[NSString stringWithFormat:@"23/08/2012 11:30:33"];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy HH:mm:ss"];
NSDate *dateRemaining = [dateFormat dateFromString:dateValueRemaining];
NSDate *pickerDate = dateRemaining;
NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit
                                                         | NSMonthCalendarUnit
                                                         | NSDayCalendarUnit)
                                               fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit
                                                         | NSMinuteCalendarUnit
                                                         | NSSecondCalendarUnit)
                                               fromDate:pickerDate];
// Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
NSLog(@"itemDate: %@", itemDate);
if (localNotif) {
    [[UIApplication sharedApplication] cancelLocalNotification:localNotif];
}
localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil) {
    return;
}
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = @"Your Time is Over";
localNotif.alertAction = @"View";
//---THIS SONG FILE IN THE NSBUNDLE FOLDER---------//
localNotif.soundName = @"s1.mp3";
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

内置应用程序(本机iOS应用程序)没有第三方iOS应用程序的限制…因此简言之..如果用户切换到静默状态,您的应用程序将不会播放声音..但此免费应用程序可以在后台播放声音,并且在用户切换到静默状态时不会静音:,你知道他们怎么做吗?不知道..虽然我建议做一个样本项目,并使用本地通知检查自己..只需要15分钟..感谢Shubhank的持续支持。事实上,我只是这样做了,我的UILocalNotification声音(26秒)在切换到静音模式后立即停止(播放)。i-iQ应用程序必须做一些其他事情来阻止声音停止播放。如果你能告诉我怎么做,我将不胜感激。谢谢。不认识的人。我知道这是做不到的。如果按一下静音键。即使铃声也不能播放。i-IQ应用程序如何播放??(疯狂的事情!!)@eeerahul:谢谢你编辑我的答案,@Tuyen Nguyen:对不起,兄弟,我不知道,但我想它不能在静音模式下播放声音,兄弟。若你们真的想谢谢我,点击向上箭头按钮thnx@TuyenNguyen:还有一件事,如果你能改变声音的模式,那么你可以做任何你想做的事……我想我永远不会发生lol。最棒的luckI也已经做了几个月了,看看吧。