我在服务器上注册设备数据,以获得推送通知.这是代码,
[NSURLConnection sendAsynchronousRequest: request
queue: _postQueue
completionHandler: ^(NSURLResponse *response, NSData *responseData, NSError *connectionError) {
if (connectionError) {
//
} else {
NSError *error = nil;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData: responseData options: NSJSONReadingMutableContainers error: &error];
}
}];
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x17057f60 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments …Run Code Online (Sandbox Code Playgroud) 我是 ios swift 的新手,
如何在闪屏期间从网络服务获取数据,
换句话说,我想让闪屏仍然出现,直到应用程序完成获取数据。
我尝试将 NSURLConnection.sendAsynchronousRequest函数放入 appdelegate 但启动画面不等待 sendAsynchronousRequest 完成
splash-screen nsurlconnection sendasynchronousrequest swift ios8
我有这个代码将json字符串发送到服务器
[NSURLConnection
sendAsynchronousRequest:req
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response,
NSData *data,
NSError *error)
{
if ([data length] >0 && error == nil)
{
NSLog(@"Done");
}
else if ([data length] == 0 && error == nil)
{
NSLog(@"Nothing was downloaded.");
self.resultLabel.text=@"Done!";
self.view.userInteractionEnabled = TRUE;
}
else if (error != nil){
NSLog(@"Error = %@", error);
}
}];
Run Code Online (Sandbox Code Playgroud)
异步请求完成后,日志在完成后几乎立即显示.但是,这段代码:
self.resultLabel.text=@"Done!";
self.view.userInteractionEnabled = TRUE;
Run Code Online (Sandbox Code Playgroud)
在UI中显示10秒钟.有人知道为什么会这样吗?
我正在使用[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)]从Web服务提取数据,但Web服务器具有自行颁发的证书,导致出现此错误:

显示错误:
NSAlert *a = [NSAlert alertWithError:error];
[a runModal];
Run Code Online (Sandbox Code Playgroud)
有没有办法忽略这个错误并继续?
目前使用来自NSURLConnection的sendAsynchronous来发布和获取请求,但无法获取响应中的状态代码.大多数帖子都建议使用NSURLConnection及其委托方法,我理解它们也是异步的.
我不明白委托如何将信息发送回调用方法(最终需要数据的方法).sendAsynchronous方法有一个我现在正在使用的回调.
我是新来的,谢谢你的帮助.
cocoa-touch http-status-code-401 nsurlconnectiondelegate sendasynchronousrequest ios6
我正在尝试使用 springboot 运行基本的异步服务。
调用请求时出现异常。不知道为什么会这样,我使用了 oracle 网站和 jersey 网站上的所有说明和代码片段。我这里有什么遗漏吗?如果您需要更多信息,请询问我,我会相应地更新问题。谢谢你。
org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.ws.rs.container.AsyncResponse]: Specified class is an interface
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:101)
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:80)
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:106)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:78)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:775)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) …Run Code Online (Sandbox Code Playgroud) ios ×2
cocoa ×1
cocoa-touch ×1
ios6 ×1
ios8 ×1
java ×1
jax-rs ×1
jersey-2.0 ×1
json ×1
objective-c ×1
spring-boot ×1
swift ×1