I receive a simple remote notification and handle it like this:
我收到一个简单的远程通知,并按如下方式处理:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
let notificationObject = JSON(userInfo)
if notificationObject["type"] == "friendRequest" {
let tab = self.window?.rootViewController as! UITabBarController
tab.selectedIndex = 1
}
}
When opened, the push notification presents a ViewController that manages a subclassed UITableView
and UITableViewCell
.
打开时,推送通知会显示一个ViewController,用于管理子类UITableView和UITableViewCell。
The UITableViewCell
makes a network call for each cell to Google API as follows:
UITableViewCell为Google API的每个单元格进行网络调用,如下所示:
let url = "https://www.googleapis.com/books/v1/volumes?q=\(isbn)&fields=items(volumeInfo(imageLinks(thumbnail),industryIdentifiers))&key=\(GOOGLE_BOOKS_API_KEY)"
Alamofire.request(.GET, url).response { response in
print(response)
The calls for each cell succeed except for the first one, which gives me:
每个单元格的调用成功除了第一个单元格,这给了我:
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost.
Are there any iOS limitations/delays/interference for network calls on launch?
在发布时网络呼叫是否有iOS限制/延迟/干扰?
1 个解决方案
#1
0
I have noticed that sometimes you need to make little delay before performing certain things that fail, in case you execute them immediately.
我注意到有时你需要在执行某些失败的事情之前稍微延迟,以防你立即执行它们。
Before calling a method, that starts building a UITableView
and corresponding cells, wrap the method call into dispatch_after
block, with delay of 0.1 seconds, which should be sufficient.
在调用方法之前,开始构建UITableView和相应的单元格,将方法调用包装到dispatch_after块中,延迟为0.1秒,这应该足够了。
This should solve your problem with the first cell. In case this helps, you can experiment with delay, trying to make it even shorter.
这应该可以解决第一个单元格的问题。如果这有帮助,您可以尝试延迟,尝试使其更短。
#1
0
I have noticed that sometimes you need to make little delay before performing certain things that fail, in case you execute them immediately.
我注意到有时你需要在执行某些失败的事情之前稍微延迟,以防你立即执行它们。
Before calling a method, that starts building a UITableView
and corresponding cells, wrap the method call into dispatch_after
block, with delay of 0.1 seconds, which should be sufficient.
在调用方法之前,开始构建UITableView和相应的单元格,将方法调用包装到dispatch_after块中,延迟为0.1秒,这应该足够了。
This should solve your problem with the first cell. In case this helps, you can experiment with delay, trying to make it even shorter.
这应该可以解决第一个单元格的问题。如果这有帮助,您可以尝试延迟,尝试使其更短。