I have a parse deployed in Heroku for my app. When I run app in simulator or on my test device after installing via xcode, everything works fine. I can fetch data and see images downloaded on initial view controller. But, whenever app is on app store review or being installed via Test Flight, Parse just stops working. I can't fetch any data and app becomes almost useless. The code looks like this:
class ListOfCategoriesViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var categories: [DisplayCategory] = []
override func viewDidLoad() {
super.viewDidLoad()
// loader
let spinner: UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
spinner.center = self.view.center
spinner.startAnimating()
view.addSubview(spinner)
//setting text
self.title = "Explore"
let query = PFQuery(className: "Category")
query.findObjectsInBackgroundWithBlock { (result: [PFObject]?, error: NSError?) -> Void in
self.categories = result as? [DisplayCategory] ?? []
spinner.stopAnimating() // loader stops here and code below never executes
for category in self.categories {
category.imageCategoryFile?.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in
let image = UIImage(data: imageData!, scale: 1.0)
category.imageCategory = image
self.tableView.reloadData()
}
}
}
}
DisplayCategory class looks like this:
class DisplayCategory: PFObject, PFSubclassing {
@NSManaged var imageCategoryFile: PFFile?
@NSManaged var titleCategory: String?
var imageCategory: UIImage?
static func parseClassName() -> String {
return "Category"
}
Any ideas what might cause this issue here? Appreciate your help.
Try adding the following in your Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
The solution was trivial. I needed to register subclass in AppDelegate and call it in didFinishLaunchingWithOptions launchOptions:
So, it now looks like this in AppDelegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
configureParse()
return true
}
func configureParse() {
DisplayCategory.registerSubclass()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.