我在Heroku中为我的应用部署了一个解析。当我通过xcode安装后在模拟器或我的测试设备上运行应用程序时,一切正常。我可以获取数据并查看在初始视图控制器上下载的图像。但是,每当应用程序在应用程序商店审查或通过Test Flight安装时,Parse就会停止工作。我无法获取任何数据,应用程序变得几乎无用。 代码如下所示:
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 DisplayCategory: PFObject, PFSubclassing {
@NSManaged var imageCategoryFile: PFFile?
@NSManaged var titleCategory: String?
var imageCategory: UIImage?
static func parseClassName() -> String {
return "Category"
}
有什么想法可能会导致这个问题吗?感谢您的帮助。
答案 0 :(得分:0)
尝试在Info.plist中添加以下内容:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
答案 1 :(得分:0)
解决方案很简单。我需要在AppDelegate中注册子类并在didFinishLaunchingWithOptions launchOptions中调用它:
所以,它现在在AppDelegate中看起来像这样:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
configureParse()
return true
}
func configureParse() {
DisplayCategory.registerSubclass()
}