Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS资源URL混乱_Ios_Uiwebview_Alassetslibrary - Fatal编程技术网

iOS资源URL混乱

iOS资源URL混乱,ios,uiwebview,alassetslibrary,Ios,Uiwebview,Alassetslibrary,我有一个如下所示的URL: assets-library//asset/asset.MOV?id=51CED0CF-223D-4606-81BB-241381BCF2E8&ext=MOV 我使用以下代码在UIWebview中播放它: NSString *localVideoHTML = @"\ <html><head>\ <style type=\"text/css\">\ body {\ background

我有一个如下所示的URL:

assets-library//asset/asset.MOV?id=51CED0CF-223D-4606-81BB-241381BCF2E8&ext=MOV
我使用以下代码在UIWebview中播放它:

    NSString *localVideoHTML = @"\
    <html><head>\
    <style type=\"text/css\">\
    body {\
    background-color: transparent;\
    color: white;\
    }\
    </style>\
    </head><body style=\"margin:0\">\
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-mp4\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>";
    NSString *html = [NSString stringWithFormat:localVideoHTML, videoId, self.frame.size.width, self.frame.size.height];
这似乎适用于某些URL,但不适用于其他URL。因此,在这一点上,我很困惑是否可以在URL指向现有文件之前确定该文件是否可能已从设备中删除,因为URL存储在核心数据数据库中以供重复使用。我从某某和其他地方的阅读中得到了这样的感觉:一个看起来像我发布的URL的URL不能被可靠地使用;然而,我一直能够毫不困难地播放如上所示的电影

因此,我的问题是:

假设我能够使用上面所示的URL执行所有测试,那么假设它将使用任何此类URL是否犯了错误

b在加载到webview之前,是否有一种简单的方法来测试URL的可访问性,因此如果它不是有效的URL,我可以在代码中处理该问题


提前感谢您提供的任何帮助。

好的,这已经解决了,如果它能帮助其他人,请继续

要测试视频在播放时是否仍在设备上,请使用以下代码:

- (void) verifyURLReachable:(NSString *) videoID
{
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library assetForURL:[NSURL URLWithString:videoID]
     resultBlock:^(ALAsset *asset)
     {
         if (!asset)
         {
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Video is Not Available on Device"
                                                             message:@"The requested video is no longer available on this iPad device. This video will be automatically removed from the current goal."
                                                            delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
             alert.tag = alertViewURLUnreachable;
             [alert show];
         }
    }
    failureBlock:^(NSError *error)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Access to Photos is Required"
                                                        message:@"To play videos that are stored on your device you must allow access to your photo and video library. This setting is made in your device setttings under 'Privacy'."
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        alert.tag = alertViewUserDeniedAccess;
        [alert show];
    }];
}
它获取资产url并对照库进行检查;如果视频可用,则“如果”!asset返回true并显示警报视图,委托将其交回视图控制器以完成,但它可以在此处执行任何需要的操作。故障块捕获用户拒绝访问设备上照片的情况

如原问题中所述,上面给出的html对于显示视频效果良好。因此,我首先检查URL是否存在,如果存在,则继续播放它。无论视频是youtube还是存储在设备上的视频,都使用相同的UIWebView子类;基本上,只有HTML和videoID是不同的。videoID包含youtube用户的youtube id,以及本地用户的资产URL


谢谢你的回复。

那么你的意思是你的一些URL出现了假阴性?您能提供一个例子吗?收件人:这在IOS8上不再有效。仍在调查原因。
- (void) verifyURLReachable:(NSString *) videoID
{
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library assetForURL:[NSURL URLWithString:videoID]
     resultBlock:^(ALAsset *asset)
     {
         if (!asset)
         {
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Video is Not Available on Device"
                                                             message:@"The requested video is no longer available on this iPad device. This video will be automatically removed from the current goal."
                                                            delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
             alert.tag = alertViewURLUnreachable;
             [alert show];
         }
    }
    failureBlock:^(NSError *error)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Access to Photos is Required"
                                                        message:@"To play videos that are stored on your device you must allow access to your photo and video library. This setting is made in your device setttings under 'Privacy'."
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        alert.tag = alertViewUserDeniedAccess;
        [alert show];
    }];
}