C# 如何在Xamarin.Forms.iOS中获得访问html文件的正确路径?
我已经创建了一个html文件,我现在正试图访问它,但我遇到了一点麻烦。当我在iOS地图中有C# 如何在Xamarin.Forms.iOS中获得访问html文件的正确路径?,c#,xamarin,path,xamarin.ios,xamarin.forms,C#,Xamarin,Path,Xamarin.ios,Xamarin.forms,我已经创建了一个html文件,我现在正试图访问它,但我遇到了一点麻烦。当我在iOS地图中有YTPlayerView iframe player.html文件时,代码当前看起来是这样的: const string HTMLTemplatePath = @"YTPlayerView-iframe-player.html"; string path = Path.Combine(NSBundle.MainBundle.BundlePath, HTMLTemplatePath); 当我尝试创建上面
YTPlayerView iframe player.html
文件时,代码当前看起来是这样的:
const string HTMLTemplatePath = @"YTPlayerView-iframe-player.html";
string path = Path.Combine(NSBundle.MainBundle.BundlePath, HTMLTemplatePath);
当我尝试创建上面的路径时,会出现以下错误消息导致崩溃:
找不到路径的一部分“/var/containers/Bundle/Application/252DA-6758-4650-88E0-F30043043/myProject.iOS.应用程序/播放器查看iframe播放器.html“
我需要如何调整才能使其正常工作?我是否需要将html文件移到其他位置(可能在共享(项目)文件夹中?)或需要调整HTMLTemplatePath字符串
这是html文件的外观:
<html>
<head>
<style>
body { margin: 0; width:100%%; height:100%%; }
html { width:100%%; height:100%%; }
</style>
</head>
<body>
<div id="player"></div>
<script src="https://www.youtube.com/iframe_api"></script>
<script>
var player;
YT.ready(function() {
player = new YT.Player('player', %%jsontemp%%);
window.location.href = 'ytplayer://onYouTubeIframeAPIReady';
});
function onReady(event) {
window.location.href = 'ytplayer://onReady?data=' + event.data;
}
function onStateChange(event) {
window.location.href = 'ytplayer://onStateChange?data=' + event.data;
}
function onPlaybackQualityChange(event) {
window.location.href = 'ytplayer://onPlaybackQualityChange?data=' + event.data;
}
function onPlayerError(event) {
window.location.href = 'ytplayer://onError?data=' + event.data;
}
</script>
</body>
</html>
正文{边距:0;宽度:100%%;高度:100%%;}
html{宽度:100%%;高度:100%%;}
var播放器;
YT.ready(函数(){
player=新的YT.player('player',%%jsontemp%%);
window.location.href=ytplayer://onYouTubeIframeAPIReady';
});
函数onReady(事件){
window.location.href=ytplayer://onReady?data=“+事件数据;
}
函数onStateChange(事件){
window.location.href=ytplayer://onStateChange?data=“+事件数据;
}
函数onPlaybackQualityChange(事件){
window.location.href=ytplayer://onPlaybackQualityChange?data=“+事件数据;
}
函数onplayerror(事件){
window.location.href=ytplayer://onError?data=“+事件数据;
}
该文件在项目中的位置?是否将其生成操作设置为内容?它现在位于我的iOS文件夹中。我在哪里可以找到“构建操作”?是否在“iOS构建”下?右键单击解决方案浏览器/pad中的文件。确定!我现在就把它设置为内容。让我们试试看!工作得很好,似乎:)我现在得到另一个错误,这是进步!谢谢