پخش پس زمینه در تبلیغات صوتی
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
این راهنما برای ناشران iOS در نظر گرفته شده است که علاقه مند به افزودن پخش آگهی صوتی پس زمینه به پیاده سازی IMA SDK خود هستند. این به برنامه اجازه می دهد تا تبلیغات را در پس زمینه درخواست کند. همچنین به برنامه اجازه میدهد وارد پسزمینه شود و به پخش آگهی تا پایان ادامه دهد.
ما پخش تبلیغات ویدیویی در پسزمینه را توصیه نمیکنیم.
پیش نیازها
- برنامه iOS با IMA SDK اجرا شده است.
- IMA SDK V3 Beta نسخه 13 یا بالاتر.
پرایمرهای مفید
اگر هنوز نیاز به پیاده سازی IMA SDK در برنامه خود دارید، راهنمای شروع ما را بررسی کنید.
اضافه کردن پخش تبلیغات پس زمینه به برنامه شما
افزودن پخش تبلیغات پسزمینه مراحل زیر را انجام میدهد:
- حالت پسزمینه صدا و پخش پخش را فعال کنید. در Xcode 6، یک هدف را انتخاب کنید، سپس در قسمت Capabilities > Background Modes ، "Audio and Airplay" را فعال کنید.

-
AVAudioSession
فعال کنید و دسته بندی آن را با AVAudioSessionCategory
که می تواند صدای پس زمینه پخش کند، مانند AVAudioSessionCategoryPlayback
تنظیم کنید. - (void)viewDidLoad {
[super viewDidLoad];
NSError *error;
[[AVAudioSession sharedInstance] setActive:YES error:&error];
if (error != nil) {
NSLog(@"Error: %@", error.localizedDescription);
}
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
if (error != nil) {
NSLog(@"Error: %@", error.localizedDescription);
}
}
- یک
IMAAdsLoader
ایجاد کنید و یک شی IMASettings
با enableBackgroundPlayback
روی YES
ارسال کنید. IMASettings *settings = [[IMASettings alloc] init];
settings.enableBackgroundPlayback = YES;
IMAAdsLoader *adsLoader = [[IMAAdsLoader alloc] initWithSettings:settings];
مهم است
برای درخواست تبلیغات پس زمینه، محتوای شما باید در حال پخش باشد. زمانی که برنامه قبل از تماس با [IMAAdsLoader requestAds:]
وارد پسزمینه میشود، ممکن است نیاز به فراخوانی دستی پخش در پخشکننده محتوا باشد.
پسزمینه کردن یک برنامه iOS بهطور خودکار پخش آگهی را متوقف میکند. اگر برنامه شما در حین پخش یک تبلیغ پسزمینه است، برای ازسرگیری پخش باید با [IMAAdsManager resume]
تماس بگیرید.
سوالات متداول
- اگر قابلیت Audio and Airplay background mode را در برنامه خود فعال نکنم چه اتفاقی می افتد؟
- اگر این حالت را انتخاب نکنید، وقتی برنامه به پسزمینه میرود، هر صدایی که توسط برنامه پخش میشود متوقف میشود. این برنامه همچنین قادر به راهاندازی هیچ صوتی در هنگام پسزمینه نیست.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis guide helps iOS publishers add background audio ad playback to their IMA SDK implementation.\u003c/p\u003e\n"],["\u003cp\u003eRequires iOS application with IMA SDK V3 Beta v13 or greater.\u003c/p\u003e\n"],["\u003cp\u003eEnable "Audio and Airplay" background mode in Xcode and activate \u003ccode\u003eAVAudioSession\u003c/code\u003e for background audio playback.\u003c/p\u003e\n"],["\u003cp\u003eCreate an \u003ccode\u003eIMAAdsLoader\u003c/code\u003e with \u003ccode\u003eenableBackgroundPlayback\u003c/code\u003e set to \u003ccode\u003eYES\u003c/code\u003e in \u003ccode\u003eIMASettings\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eBackgrounding pauses ad playback; resume with \u003ccode\u003e[IMAAdsManager resume]\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Play background in audio ads\n\nThis guide is intended for iOS publishers interested in adding background **audio** ad playback to their IMA SDK implementation. This allows the app to request ads in the background. It also allow the app to enter the background and continue to play an ad to completion.\n\nWe do not recommend playing video ads in the background.\n\nPrerequisites\n-------------\n\n\u003cbr /\u003e\n\n- iOS application with the IMA SDK implemented.\n- IMA SDK V3 Beta v13 or greater.\n\n\u003cbr /\u003e\n\nHelpful primers\n---------------\n\nIf you still need to implement the IMA SDK in your app, check out our [Get Started guide](/interactive-media-ads/docs/sdks/ios/client-side).\n\nAdding background ad playback to your app\n-----------------------------------------\n\nAdding background ad playback takes the following steps:\n\n1. Enable the **Audio and Airplay** background mode. In Xcode 6, select a target, then under **Capabilities \\\u003e Background Modes**, enable \"Audio and Airplay\".\n2. Activate the `AVAudioSession`, and set its category with an `AVAudioSessionCategory` that can play background audio, such as `AVAudioSessionCategoryPlayback`. \n\n```objective-c\n- (void)viewDidLoad {\n [super viewDidLoad];\n\n NSError *error;\n [[AVAudioSession sharedInstance] setActive:YES error:&error];\n if (error != nil) {\n NSLog(@\"Error: %@\", error.localizedDescription);\n }\n\n [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];\n if (error != nil) {\n NSLog(@\"Error: %@\", error.localizedDescription);\n }\n}\n```\n3. Create an `IMAAdsLoader`, passing in an `IMASettings` object with `enableBackgroundPlayback` set to `YES`. \n\n```objective-c\n IMASettings *settings = [[IMASettings alloc] init];\n settings.enableBackgroundPlayback = YES;\n IMAAdsLoader *adsLoader = [[IMAAdsLoader alloc] initWithSettings:settings];\n```\n\nImportant\n---------\n\nTo make background ad requests, your content must be playing. This may require manually calling play on the content player when the app enters the background before calling `[IMAAdsLoader requestAds:]`.\n\nBackgrounding an iOS app automatically pauses ad playback. If your app is backgrounded while playing an ad, you need to call `[IMAAdsManager resume]` to resume playback.\n\nFAQ\n---\n\nWhat happens if I don't enable the Audio and Airplay background mode capability in my app?\n: If you don't select this mode, any audio being played by the app stops when the app moves to the background. The app is also not able to launch any audio while backgrounded."]]