Nurzhan Ospanov Nurzhan Ospanov - 3 months ago 12
iOS Question

Parse doesn't work in app release version, but works on simulator or when installed on device via xcode

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.

Answer

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()

}
Comments