iOS - UIWebView not working due to parsing error

跟風遠走 提交于 2019-11-30 00:06:43
Richard Poirier

Use:

http://www.youtube.com/v/XXXXXXX

instead of:

http://www.youtube.com/watch?v=XXXXXXX

Found here: https://devforums.apple.com/message/705665#705665

Maybe my method for translating youtube URL to correct format will help you:

+ (NSString*)getYTUrlStr:(NSString*)url
{   
    if (url == nil)
        return nil;

    NSString *retVal = [url stringByReplacingOccurrencesOfString:@"watch?v=" withString:@"v/"];

    NSRange pos=[retVal rangeOfString:@"version"];
    if(pos.location == NSNotFound)
    {
        retVal = [retVal stringByAppendingString:@"?version=3&hl=en_EN"];
    }
    return retVal;
}

I solved it using the following HTML:

<!doctype html>\
<html>\
<style>body{padding:0;margin:0;}</style>\
<iframe width=\"320\" height=\"367\" src=\"http://www.youtube.com/embed/rVd0XWALswk?rel=0\" frameborder=\"0\" allowfullscreen></iframe>\
</html>

It has nothing to do with using short URL nor the YouTube URL. It's probably using the embed tag and using the type application/x-shockwave-flash. It's now working perfectly fine on iOS 6 GM.

Chances are, with that error, there's an array somewhere that you're going through, but at some point you call some method that ends up trying to reach something that's beyond the array.

For example, code like this would produce an out-of-bounds error:

NSArray *array = [[NSArray alloc] initWithObjects:objInPositionZero, objInPositionOne, objInPositionTwo, nil];
NSObject *obj;

for (int i=0; i<3, i++)
{
    obj = [array objectAtIndex: (i+6)
}
//Do something with obj.

would produce an NSRangeException, because the program is trying to return an item from an index that doesn't actually exist in the array.

So check through all your arrays and make sure that's not happening.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!