تشغيل الإعلانات الصوتية في الخلفية
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
هذا الدليل موجَّه إلى ناشري iOS المهتمين بإضافة تشغيل الإعلانات الصوتية في الخلفية إلى عملية تنفيذ حزمة تطوير البرامج لإعلانات الوسائط التفاعلية. يتيح هذا الإجراء للتطبيق طلب الإعلانات في الخلفية. ويسمح أيضًا للتطبيق بالدخول في الخلفية ومواصلة تشغيل إعلان حتى الاكتمال.
لا ننصح بتشغيل إعلانات الفيديو في الخلفية.
المتطلبات الأساسية
- تطبيق iOS مع تنفيذ حزمة تطوير البرامج لإعلانات الوسائط التفاعلية.
- الإصدار 3 من حزمة تطوير البرامج لإعلانات الوسائط التفاعلية، الإصدار التجريبي 13 أو الإصدارات الأحدث
مواد تمهيدية مفيدة
إذا كنت لا تزال بحاجة إلى تنفيذ حزمة IMA SDK في تطبيقك، يُرجى مراجعة دليل البدء.
جارٍ إضافة تشغيل الإعلانات في الخلفية إلى تطبيقك
يجب اتخاذ الخطوات التالية لإضافة الإعلان في الخلفية:
- فعِّل وضع الخلفية الصوت وAirplay. في Xcode 6، اختَر هدفًا، ثم ضمن الإمكانات >. أوضاع الخلفية: فعِّل خيار "الصوت و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]
لاستئناف التشغيل.
الأسئلة الشائعة
- ماذا يحدث في حال لم أفعّل ميزة "الصوت والتشغيل في الخلفية" في تطبيقي؟
- في حال عدم اختيار هذا الوضع، سيتوقف أي صوت يشغّله التطبيق عندما ينتقل التطبيق إلى الخلفية. لا يمكن أيضًا للتطبيق تشغيل أي محتوى صوتي أثناء تشغيله في الخلفية.
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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."]]