• 如何让用户在用webview访问网页时嵌入我们自己的内容


    代码如下:
            NSString *strUrl=[textField text];
        NSString *urlString=[NSString stringWithFormat:strUrl];
        NSURL *url=[NSURL URLWithString:urlString];
        NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url
                                                  cachePolicy:NSURLRequestReturnCacheDataElseLoad
                                              timeoutInterval:60];
        NSData *urlData;
        NSURLResponse *response;
        NSError *error;
        urlData=[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
        NSString *dataStr =[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
        dataStr = [dataStr substringToIndex:[dataStr length] - 16];
        dataStr = [dataStr stringByAppendingString:@"<p>hello world navy did it </p></body></html>"];
        NSLog(@"%@",dataStr);
        const char *cString = [dataStr UTF8String];
        NSData *myData= [[NSData alloc]initWithBytes:cString length:strlen(cString)+1];
        [self.myWebView loadData:myData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:url];

    这个代码我是在UICatalog中WebViewController中添加的,有人要这功能,小生就乘机学习了下,嫌麻烦,直接用的UICatalog代码.见谅.
    此代码功能在于:在你访问的网页左下角加了hello world navy did it.几个字.
    不希望做流氓功能.一切以用户为主.

     
  • 相关阅读:
    LeetCode 297. 二叉树的序列化与反序列化
    LeetCode 14. 最长公共前缀
    LeetCode 1300. 转变数组后最接近目标值的数组和
    bigo一面凉经
    LeetCode 128.最长连续序列
    LeetCode中二分查找算法的变种
    LeetCode 93. 复原IP地址
    LeetCode 1004. 最大连续1的个数 III
    LeetCode 1282. 用户分组
    多线程理解
  • 原文地址:https://www.cnblogs.com/daishuguang/p/3669874.html
Copyright © 2020-2023  润新知