0

我试过这段代码但没有用,

-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"paying with coins and bills" ofType:@"wav"];
AudioServicesCreateSystemSoundID(CFBridgingRetain([NSURL fileURLWithPath:soundPath]), &(soundID));
AudioServicesPlaySystemSound (soundID);

}

它只会在我运行 xcode 项目时播放。

我的要求是,在我的 ipad 中,每当打开我的应用程序时,我都需要播放声音。请帮我

4

1 回答 1

0

您可以尝试将您的代码移动到 AppDelegate.m

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

当您的应用程序处于活动状态时,将调用此方法,这可能适合您的情况。

于 2013-10-24T03:08:13.347 回答