我试图在iOS应用程序的Webview中加载一个自签名的url。其他网址正在我的webview中完美加载。
我已在info.plist文件中添加了文件,但出现错误:-
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
这是我的全部错误:-
2019-01-08 12:26:52.386721 + 0530 Webview演示[761:27005] TIC SSL Trust 错误[2:0x282e90480]:3:0
2019-01-08 12:26:52.405216 + 0530 Webview演示[761:27005] NSURLSession / NSURLConnection HTTP加载失败 (kCFStreamErrorDomainSSL,-9807)
2019-01-08 12:26:52.405283 + 0530 Webview演示[761:27005]任务 。<0> HTTP加载失败(错误 代码:-1202 [3:-9807])
2019-01-08 12:26:52.405519 + 0530 Webview演示[761:27003] NSURLConnection完成,错误-代码-1202
我是iOS的新手,请帮助我理解和解决问题。
这是我的ViewController:-
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://stackoverflow.com")
if let unwrappedUrl = url{
let request = URLRequest(url : unwrappedUrl)
let session = URLSession.shared
let task = session.dataTask(with: request) { (data, response , error) in
if error == nil {
DispatchQueue.main.async {
self.webView.loadRequest(request)
}
}
}
task.resume()
}
}
}
答案 0 :(得分:-1)
您所要做的就是添加一些编码内容,而不是添加键-Info.plist中的值
让serverTrustPolicies:[String:ServerTrustPolicy] = [ “您的网站”:.disableEvaluation ]
在会话管理器中添加以上内容。
var处置:URLSession.AuthChallengeDisposition = .performDefaultHandling
如果您使用alamofire,则可以使用以下方法,
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.majesco</groupId>
<artifactId>customerportal</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.majesco</groupId>
<artifactId>commonservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>commonservice</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId>
<version>3.8.1</version> <scope>test</scope> </dependency> -->
<dependency>
<groupId>com.majesco</groupId>
<artifactId>objectmodel</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.majesco</groupId>
<artifactId>logger</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- Simple Json -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<!-- Hibernate Core API -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.5.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.common/hibernate-commons-annotations -->
<!-- <dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.1.Final</version>
</dependency> -->
<!-- postgresql Driver -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160212</version>
</dependency>
<!-- EHCache Core APIs -->
<!-- <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-core</artifactId>
<version>2.6.9</version> </dependency> -->
<!-- Hibernate EHCache API -->
<!-- <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-ehcache</artifactId>
<version>4.3.5.Final</version> </dependency> -->
<!-- EHCache uses slf4j for logging -->
<!-- <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId>
<version>1.7.5</version> </dependency> -->
<!-- @log4j2 xml dependency -->
<!-- <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId>
<version>2.0</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId> <version>2.0</version> </dependency> -->
<!-- javax.mail dependency -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<!-- slf4j-api dependency -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<!-- slf4j-simple dependency -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
</dependency>
<!-- pgichecksum dependency -->
<dependency>
<groupId>com.billdesk.pgidsk</groupId>
<artifactId>pgichecksum</artifactId>
<version>1.0</version>
</dependency>
<!-- esbservicesclient dependency -->
<dependency>
<groupId>esbservices_client</groupId>
<artifactId>esbservicesclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbpolicysearchclient dependency -->
<dependency>
<groupId>esbpolicysearch_client</groupId>
<artifactId>esbpolicysearchclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbcustomerserviceclient dependency -->
<dependency>
<groupId>esbcustomerservice_client</groupId>
<artifactId>esbcustomerserviceclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbcustomerserviceclient dependency -->
<dependency>
<groupId>esbaccountservice_client</groupId>
<artifactId>esbaccountserviceclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbgenericserviceclient dependency -->
<dependency>
<groupId>esbgenericservice_client</groupId>
<artifactId>esbgenericserviceclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbgenericintegrationclient dependency -->
<dependency>
<groupId>genericintegration_client</groupId>
<artifactId>esbgenericintegrationclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- Start pooja added 040817-->
<dependency>
<groupId>esbusermanagement_client</groupId>
<artifactId>esbusermanagementclient</artifactId>
<version>0.0.1-SNAPSHOT </version>
</dependency>
<!-- End pooja added 040817-->
<!-- Start pooja added 050917-->
<dependency>
<groupId>esbrenewalstatus_client</groupId>
<artifactId>esbrenewalstatusclient</artifactId>
<version>0.0.1-SNAPSHOT </version>
</dependency>
<!-- End pooja added 050917-->
<!-- updateCustomerService<07062018> dependency -->
<dependency>
<groupId>esbupdatecustomer_service</groupId>
<artifactId>esbupdatecustomerservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- updateCustomerService<07062018> dependency -->
<!-- esbdatabasefetchservice dependency -->
<dependency>
<groupId>esbdatabasefetchservice_client</groupId>
<artifactId>esbdatabasefetchservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- esbdatabasefetchservice dependency -->
<!-- base64 commons-codec -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>5.0.0</version>
</dependency>
<!-- Added for send email functionality -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<!-- 1574973 start -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.annotation</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.metatype.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<!-- 1574973 end -->
</dependencies>
<build>
<resources>
<!-- standard Maven folder -->
<resource>
<directory>src/main/resources</directory>
</resource>
<!-- plus root folder -->
<resource>
<directory>.</directory>
<includes>
<include>plugin.xml</include>
<include>META-INF/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<configuration>
<unpackBundle>true</unpackBundle>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<!-- <Export-Package>com.majesco.portal.service.*;version=${project.version}</Export-Package> -->
<!-- <Import-Package>*</Import-Package> -->
<!-- <Import-Package>!*</Import-Package> <Embed-Dependency>*</Embed-Dependency>
<Bundle-ClassPath>.</Bundle-ClassPath> -->
<!-- <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy> -->
<!-- <Embed-Dependency>*</Embed-Dependency> -->
<Embed-Dependency>!objectmodel,*</Embed-Dependency>
<Export-Package>com.majesco.dcf.common.*,com.majesco.dcf.pg.*,com.majesco.dcf.receipt.*,com.unotechsoft.stub.*,stub.unotechsoft.com.wsdl*,org.apache.http.impl.client*,org.apache.http.ssl*,org.apache.http*,org.apache*,org.datacontract.schemas*</Export-Package>
<Import-Package>org.osgi.framework,org.hibernate.*,com.majesco.dcf.pa.json,org.json.*,*;resolution:=optional</Import-Package>
<!-- <Export-Package>${export.packages}</Export-Package> -->
<!-- <Export-Package>!com.majesco.service.activator,com.majesco.service.*;version=${project.version}</Export-Package> -->
<Bundle-Activator>com.majesco.dcf.common.service.activator.CommonServiceBundleActivator</Bundle-Activator>
</instructions>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<excludePackageNames>com.majesco.dcf.common.util*,com.majesco.dcf.common.service.activator*,com.majesco.dcf.common.entity*,com.majesco.dcf.common.service.impl*,com.majesco.dcf.pg.entity*,com.majesco.dcf.pg.service*,com.majesco.dcf.pg.util*,com.majesco.dcf.pg.billdesk.impl*,com.majesco.dcf.receipt.util*</excludePackageNames>
</configuration>
</plugin>
</plugins>
</build>
</project>