הפעלת רקע במודעות אודיו
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
מדריך זה מיועד לבעלי אתרים שמשתמשים ב-iOS שרוצים להוסיף הפעלת מודעות אודיו ברקע להטמעה של IMA SDK. ההרשאה הזו מאפשרת לאפליקציה לבקש מודעות ברקע. היא גם מאפשרת לאפליקציה להיכנס לרקע ולהמשיך להפעיל מודעה עד לסופה.
אנחנו לא ממליצים להפעיל מודעות וידאו ברקע.
דרישות מוקדמות
- אפליקציה ל-iOS שבה הוטמעו IMA SDK.
- IMA SDK V3 Beta גרסה 13 ואילך.
ספרי לימוד למתחילים
אם אתם עדיין צריכים להטמיע את IMA SDK באפליקציה, תוכלו לעיין במדריך לתחילת העבודה.
הוספת הפעלה של מודעות ברקע לאפליקציה
כדי להוסיף הפעלה של מודעות ברקע:
- מפעילים את מצב הרקע אודיו ו-Airplay. ב-Xcode 6, בוחרים יעד ואז בקטע Capabilities > מצבים ברקע, מפעילים את האפשרות 'אודיו ו-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]
כדי להמשיך את ההפעלה.
שאלות נפוצות
- מה קורה אם לא מפעילים את האפשרויות של מצב רקע לאודיו ו-Airplay באפליקציה?
- אם לא תבחר במצב הזה, כל האודיו שהאפליקציה מפעילה תיפסק כשהאפליקציה עוברת לרקע. בנוסף, אין לאפליקציה אפשרות להפעיל אודיו כשהיא ברקע.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-31 (שעון UTC).
[null,null,["עדכון אחרון: 2025-08-31 (שעון UTC)."],[[["\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."]]