Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.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/ruby/24.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
Ios 无法在应用程序标识背景期间暂停音频_Ios_Avaudioplayer_Nstimer_Appdelegate - Fatal编程技术网

Ios 无法在应用程序标识背景期间暂停音频

Ios 无法在应用程序标识背景期间暂停音频,ios,avaudioplayer,nstimer,appdelegate,Ios,Avaudioplayer,Nstimer,Appdelegate,我不能更改值或更改任何声明的变量或对象。有人知道怎么了吗 在我的应用程序委托方法中 - (void)applicationDidEnterBackground:(UIApplication *)application { MainPage *mp = [[MainPage alloc]init]; mp.newTime = [[NSDate date] timeIntervalSinceDate:mp.date]; [mp.timer invalidate];

我不能更改值或更改任何声明的变量或对象。有人知道怎么了吗

在我的应用程序委托方法中

- (void)applicationDidEnterBackground:(UIApplication *)application
{

    MainPage *mp = [[MainPage alloc]init];

    mp.newTime = [[NSDate date] timeIntervalSinceDate:mp.date];
    [mp.timer invalidate];
    mp.switchT = 1;
    mp.playBarButton.enabled = YES;
    mp.pauseBarButton.enabled = NO;
    mp.stopBarButton.enabled = YES;
   [mp.avPlayer pause];

}
上述操作均未执行。在mainpage.h文件中,我声明如下:

@property (nonatomic, retain) AVAudioPlayer *avPlayer;
@property (strong, retain) NSTimer *timer;
@property (strong, retain) NSDate *date;
@property (nonatomic) NSTimeInterval newTime;
@property (nonatomic) NSInteger switchT;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *playBarButton;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *pauseBarButton;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *stopBarButton;
当然,在我的实现文件中,这些都是合成的,并且与mainpage.m中的代码配合得很好,只是不在我的appDelegate文件中。有人看到问题了吗?请注意,这是一个功能齐全的应用程序,一切正常,只是无法在我的ApplicationIdentinterBackground方法中执行以下代码,我假设这就是我的属性的生成方式?在应用程序委托中编写的代码也没有错误。

此主页*mp=[[MainPage alloc]init];创建一个新的主页对象。更改一个对象中的值不会影响其他MainPage对象的显示

给你的应用程序委托一个对你实际显示的对象的引用,或者在主页内放置一个后台通知处理程序,以便它可以自己工作。

此主页*mp=[[MainPage alloc]init];创建一个新的主页对象。更改一个对象中的值不会影响其他MainPage对象的显示

NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; // and later
 - (void) goBackground { [timer invalidate], timer = nil; }

给你的应用程序委托一个对你实际显示的对象的引用,或者在主页内放置一个后台通知处理程序,这样它就可以自己工作。

有效点,但即使我这样做[mp.self pause:nil];这是我的暂停方法,它会触发该方法,但其中的操作不会执行,只返回,nil,null,nan等。你能告诉我我的代码提供了你的意思吗。谢谢我真的被这个问题难住了。这很有意义,因为你已经创建了一个有效的对象,所以它的方法和变量是存在的。为了向您展示如何修复现有主页,我必须知道如何以及在何处创建现有主页。或者,正如我所说的:在主页中放置一个后台通知处理程序。ApplicationIdentinterBackground的文档应提供匹配通知的名称。谢谢。我找到了。我就是这样做的[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@SelectorBackground名称:UIApplicationIdentinterBackgroundNotification对象:nil];//稍后:-void goBackground{[timer invalidate],timer=nil;}有效点,但即使我这样做[mp.self pause:nil];这是我的暂停方法,它会触发该方法,但其中的操作不会执行,只返回,nil,null,nan等。你能告诉我我的代码提供了你的意思吗。谢谢我真的被这个问题难住了。这很有意义,因为你已经创建了一个有效的对象,所以它的方法和变量是存在的。为了向您展示如何修复现有主页,我必须知道如何以及在何处创建现有主页。或者,正如我所说的:在主页中放置一个后台通知处理程序。ApplicationIdentinterBackground的文档应提供匹配通知的名称。谢谢。我找到了。我就是这样做的[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@SelectorBackground名称:UIApplicationIdentinterBackgroundNotification对象:nil];//以及更高版本:-void goBackground{[timer invalidate],timer=nil;}
NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; // and later
 - (void) goBackground { [timer invalidate], timer = nil; }