嗨我正在尝试使用WKWebView加载一个主要Bundle中的html,这与UIWebView完美配合,但现在我有一个错误,html中的文件没有加载在控制台中发送错误:"XMLHttpRequest无法加载"
这是嵌入内容的http://proyectoshm.com/esferas/dosaguas/dosaguascitta.html示例.
我的代码:
let folder = "maquetas/esferas/\(esfera)"
let resourcePath = Bundle.main.resourcePath
let subdir = URL(fileURLWithPath:resourcePath!).appendingPathComponent(folder, isDirectory: true)
guard let path = Bundle.main.path(forResource: "index", ofType: "html", inDirectory: folder) else {
print("no se encontró path")
return
}
print(subdir.path)
let url = NSURL.fileURL(withPath: path)
print(url.path)
vistaweb = WKWebView(frame: self.view.frame)
vistaweb.loadFileURL(url, allowingReadAccessTo: subdir)
self.view.addSubview(vistaweb)
Run Code Online (Sandbox Code Playgroud) 我正在通过使用流式传输视频(.m3u8) AVPlayer
let url = URL(string: "http:myUrl.m3u8")
let player = AVPlayer(url: url!)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = videoView.bounds
playerLayer.backgroundColor = UIColor.purple.cgColor
videoView.layer.addSublayer(playerLayer)
player.play()
Run Code Online (Sandbox Code Playgroud)
我需要将流视频保存到图库。我注意到在下面的委托中保存了缓存视频路径。
func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didFinishDownloadingTo location: URL) {
// Do not move the asset from the download location
UserDefaults.standard.set(location.relativePath, forKey: "assetPath")
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下代码从UserDefaults获取网址路径时,
let path = UserDefaults.standard.value(forKey: "assetPath")
Run Code Online (Sandbox Code Playgroud)
结果是:
图书馆/com.apple.UserManagedAssets.s9Giec/video_streaming_title_3E90DD91830B8992.movpkg
我在此问题的答案中找到.movpkg文件夹结构

扩展名为“ '.movpkg' 如何将视频转换为mp4并保存到图库”。
该movpkg文件包含.frag文件。如果有任何答案可以将.frag文件转换为mp4文件,则可以接受。
我可以AVAsset从.movpkgURL 创建一个,因此问题“如何将AVAsset转换为mp4文件”的答案也可以接受。
对于想要帮助的人,我在这里创建了一个仓库
https://github.com/trungducc/stackoverflow/tree/movpkg-to-mp4 …
以前,我使用这种方法以编程方式设置音量:
MPVolumeView *volumeView = [[MPVolumeView alloc] init];
UISlider *volumeViewSlider = nil;
for (UIView *view in [volumeView subviews])
{
if ([view.class.description isEqualToString:@"MPVolumeSlider"])
{
volumeViewSlider = (UISlider *)view;
break;
}
}
[volumeViewSlider setValue:0.5 animated:YES];
[volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
直到iOS 11.4它运行良好(即使在iOS 11.3上),但在iOS 11.4上却没有.体积值保持不变.有人可以帮助解决这个问题吗?谢谢.
我希望有一个UIActionSheet自定义,UIAlertAction但似乎自定义UIAlertAction不合法.
UIAlertController类旨在按原样使用,不支持子类化.此类的视图层次结构是私有的,不得修改.
所以我正在尝试创建一个看起来完全一样的视图UIActionSheet.通过使用Debug View Hierarchy,我可以知道Apple如何应用层次结构,约束,颜色UIActionSheet来完成他们所做的事情.
我可以创建除了UIActionSheet背景之外的所有东西.这是一个包含非透明视图和视图的视图UIVisualEffectView.
该UIVisualEffectView重叠不透明的看法,但不知何故UIVisualEffectView仍然有效.
UIVisualEffectView下面有一个不透明的时候怎么还能工作呢?如果有可能,我怎么能做这样的事情?
注意:背景UIActionSheet不仅仅是一个UIVisualEffectView.请不要给出这样的答案.
我正在创建一个叠加层,它将覆盖屏幕上所有显示的视图.即使在rootViewController更改,推送或呈现的情况下,此叠加始终显示.
我的想法是
CustomWindow哪个是子类UIWindow.在更换默认之后window的UIApplication有CustomWindow,创建一个新的rootViewController为我的新窗口.CustomWindow,我有一个overlay(是UIView).Overlay浅灰色,带有阿尔法,每个事件overlay都会传递到下面的视图.CustomWindow添加一个新的子视图时,我都会把它overlay带到前面.它确保overlay在每种情况下都是最重要的.CustomWindow
@implementation CustomWindow
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_overlay = [[UIView alloc] initWithFrame:self.bounds];
_overlay.userInteractionEnabled = NO;
_overlay.backgroundColor = [UIColor lightGrayColor];
_overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:_overlay];
}
return self;
}
- (void)didAddSubview:(UIView *)subview {
[super didAddSubview:subview];
[self bringSubviewToFront:_overlay];
} …Run Code Online (Sandbox Code Playgroud) 我有一个带有内容偏移的水平 UICollectionView,以便每个元素(包括最左边的项目)都可以滚动到中心:
let cvOffset = (UIScreen.main.bounds.width - tileSize) / 2
collectionView.contentInset = UIEdgeInsets(top: 0, left: cvOffset, bottom: 0, right: cvOffset)
collectionView.scrollIndicatorInsets = UIEdgeInsets(top: 0, left: cvOffset, bottom: 0, right: cvOffset)
Run Code Online (Sandbox Code Playgroud)
但是,当我使用scrollToItem方法时,它只适用于右半部分的项目。如果我选择左半部分的任何项目,则会输入第一个单元格。你知道为什么吗?
collectionView.scrollToItem(at: IndexPath.init(row: sender.tag, section: 0), at: .centeredHorizontally, animated: true)
Run Code Online (Sandbox Code Playgroud) 据我所知,WKWebView默认情况下会为所有加载的资源设置缓存。关于如何从WKWebView中删除缓存的资源有几篇文章?但我找不到有关从中获取信息的方法的任何帖子WKWebView。
例如,当我WKWebView用来加载此url时,它会显示一个pdf文件,而我要获取的WKWebView是在完全加载url之后共享此pdf文件
我已经在Chrome上进行了检查,如果我想从上面的链接共享文件,它将在显示共享对话框后再次请求并从url下载内容。这意味着他们不会从当前WKWebView(缓存的资源)中获取它。
但是在Safari上,它们以某种方式在单击“共享”按钮后立即显示“共享”对话框,并且看起来好像无需再次下载。我认为他们从缓存或其他地方获取pdf文件WkWebView并共享它。
理解该问题的另一种方法是如何获取在WKWebView上显示的文件而无需再次下载内容?

如果问题没有足够的答案信息,请随时发表评论,我将使其更加清楚。
在 Windows server 2008 Service Pack2(x86) 机器上运行 .net core 自包含部署包,失败并显示消息“过程入口点 RaiseFailFastException 无法在动态链接库 KERNEL32.dll 中定位”
重现问题的步骤:
上面创建的自包含包在 Windows 7(x64) 中按预期工作,但在 Windows 2008 Service Pack 2 中不能正常工作。我的问题是,Windows 2008 是否支持 .net core 2.0 自包含应用程序?如果支持,如何定位KERNEL32.dll?
我正在按照Apple Docs实施 HLS 流
但是我面临的问题是在用户终止应用程序时恢复下载。如果下载正在进行并说它已完成 50% 并且用户终止应用程序或应用程序因任何原因被系统终止,并且当应用程序再次活动时,didCompleteWithError则调用URL 会话委托
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
}
Run Code Online (Sandbox Code Playgroud)
在这里我没有部分下载的文件路径或恢复任务的能力。
通过以下委托调用完成下载后,将调用下载文件的唯一位置
func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didFinishDownloadingTo location: URL) {
}
Run Code Online (Sandbox Code Playgroud)
现在医生说要使用
downloadSession.getAllTasks { tasksArray in }
Run Code Online (Sandbox Code Playgroud)
但不幸的是,它不会恢复下载
所以我的问题是
据我所知,在使用并发或多线程时设置变量属性并不安全,但我不能使用下面的代码产生崩溃。
\n\nclass Node {\n var data = 0\n}\n\nvar node = Node()\nlet concurrentQueue = DispatchQueue(label: "queue", attributes: .concurrent)\n\nfor i in 0...1000 {\n concurrentQueue.async {\n node.data = i // Should get crash at this line\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n感谢@MartinR 在评论中指出。
\n\n\n\n\n启用\xe2\x80\x9cThread Sanitizer\xe2\x80\x9d,它会立即报告错误。
\n
EXC_BAD_ACCESS KERN_INVALID_ADDRESS如果更改data为引用类型,代码会崩溃。它并不总是发生,但有时会发生。例如:
class Data {}\n\nclass Node {\n var data = Data() // Use reference type instead of value type\n}\n\nvar node = Node()\nlet concurrentQueue = DispatchQueue(label: "queue", attributes: .concurrent)\n\nfor …Run Code Online (Sandbox Code Playgroud) ios ×9
swift ×8
objective-c ×5
wkwebview ×2
.net-core ×1
mpvolumeview ×1
uikit ×1
uiwebview ×1