嵌入式音频无法在 iPad 的 UIWebView 中播放,但在 iPhone、objective C 中播放良好

Embedded audio wont play in UIWebView on iPad but plays well in iPhone, objective C

我正在下载网页并通过may app存储;这样我就可以通过我的应用程序离线访问它。我正在 UIWebView 中加载该网页 (.html)。我正在点击播放音频或视频。如果该网页包含视频,则它可以在所有设备(iPhones 和 iPads)上正常播放。但是当我访问一个有音频的网页时;然后该音频在 iPhone 上成功播放;但在 iPad 上(在设备和模拟器上也是如此)它不会在 UIWebView 中播放音频文件。我该怎么做?

    NSString *userAgentString = @"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36";
    NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:userAgentString,@"UserAgent", nil];

    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];

添加此代码当您将请求加载到您的网络视图时.. 如果你加上你的代码会更好。

更新:

试试下面的代码:

webView.scalesPageToFit = 是;

添加这个! 如果您的网络视图框架是整个屏幕。 然后试试下面的代码:

webView.frame=self.view.bounds;

@Vicky_Vignesh 你的回答部分正确(无论如何感谢提供基础)。您需要使用 UserAgent 字符串提供设备类型和 OS 版本。我是这样做的:

    NSString *userAgentString = @"Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1";
    NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:userAgentString,@"UserAgent", nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];