gpt4 book ai didi

ios - 未调用handleWatchKitExtensionRequest 的问题?

转载 作者:行者123 更新时间:2023-11-30 14:04:35 25 4
gpt4 key购买 nike

我正在尝试更新我的 watch 套件应用程序以添加一些从 JSON 文件解析的数据。我正在结合从 Parse 获取一些数据来执行此操作。

我收到错误:

The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]

我尝试调试 handleWatchKitExtensionRequest 但它没有崩溃,并且由于某种原因我添加的 println 从未打印。

这是我的代码:

func application(application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: (([NSObject : AnyObject]!) -> Void)!) {
var favouritesArrayDefaults: NSMutableArray! = [""]

println("1")
var keyStore = NSUbiquitousKeyValueStore()
if keyStore.arrayForKey("FavouritesList") != nil {
let tempFavourites: NSArray = keyStore.arrayForKey("FavouritesList")!
favouritesArray = tempFavourites.mutableCopy() as! NSMutableArray
} else {
println("3")
}

println(favouritesArrayDefaults)

if let pfqueryRequest: AnyObject = (userInfo as? [String: AnyObject])?["parkName"] {
println("HELLO")

let taskID = beginBackgroundUpdateTask()
//Must start and end task to allow time for query to complete

var name = ""
var waitTime = ""
var hasWaitTime = false
var fastPass = false
var heightRestriction = false
var singleRider = false
var disabledAccess = false
var mustSee = false
var fastPassTime = ""

var namesArray: [String] = []
var waitTimesArray: [String] = []
var favouritesArray: [String] = []
var hasWaitTimeArray: [Bool] = []
var fastPassArray: [Bool] = []
var heightRestrictionArray: [Bool] = []
var singleRiderArray: [Bool] = []
var disabledAccessArray: [Bool] = []
var mustSeeArray: [Bool] = []
var fastPassTimeArray: [String] = []

var query = PFQuery(className: pfqueryRequest as! String)
query.orderByAscending("Name")
var objects = query.findObjects()

if let objects = objects as? [PFObject] {
for object in objects {
name = (object.objectForKey("Name") as? String)!
waitTime = (object.objectForKey("WaitTime") as? String)!
hasWaitTime = (object.objectForKey("HasWaitTime") as? Bool)!
fastPass = (object.objectForKey("FastPass") as? Bool)!
heightRestriction = (object.objectForKey("HeightRestriction") as? Bool)!
singleRider = (object.objectForKey("SingleRider") as? Bool)!
disabledAccess = (object.objectForKey("DisabledAccess") as? Bool)!
mustSee = (object.objectForKey("MustSee") as? Bool)!

namesArray.append(name)
waitTimesArray.append(waitTime)
hasWaitTimeArray.append(hasWaitTime)
fastPassArray.append(fastPass)
heightRestrictionArray.append(heightRestriction)
singleRiderArray.append(singleRider)
disabledAccessArray.append(disabledAccess)
mustSeeArray.append(mustSee)
}

var urlString = (DataManager.sharedInstance.getParkByName(pfqueryRequest as! String)?.dataSource)!

if let url = NSURL(string: urlString) {
if let data = NSData(contentsOfURL: url, options: .allZeros, error: nil) {
let json = JSON(data: data)

for count in 0...json.count - 1 {
let rideName: JSON = json[count]["name"]
let waitTime: JSON = json[count]["waitTime"]
var fastPassTime: JSON = json[count]["fastPass"]

if find(namesArray, rideName.string!) != nil {
let index = find(namesArray, rideName.string!)

var modifiedWaitTime = "".join(waitTime.string!.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet))

if waitTime == "Down" || waitTime == "Closed" {
modifiedWaitTime = "Closed"
}

if fastPassTime.string == nil {
fastPassTime = "Unavailable"
} else if fastPassTime.string == "N/A" {
fastPassTime = "Expired"
}

waitTimesArray.removeAtIndex(index!)
waitTimesArray.insert(waitTime.string!, atIndex: index!)

fastPassTimeArray.removeAtIndex(index!)
fastPassTimeArray.insert(fastPassTime.string!, atIndex: index!)
}
}
}
}

for favourite in favouritesArrayDefaults {
favouritesArray.append(favourite as! String)
}

println(fastPassTimeArray)
reply(["success": true, "name": namesArray, "waitTime": waitTimesArray, "hasWaitTime": hasWaitTimeArray, "favourites": favouritesArray, "fastPass": fastPassArray, "heightRestriction": heightRestrictionArray, "singleRider": singleRiderArray, "disabledAccess": disabledAccessArray, "mustSee": mustSeeArray, "fastPassTime": fastPassTimeArray])

endBackgroundUpdateTask(taskID)
}
} else if let pfqueryRequest: AnyObject = (userInfo as? [String: AnyObject])?["parkNameSubmit"] {
let taskID = beginBackgroundUpdateTask()

var query = PFQuery(className: pfqueryRequest as! String)
//query.orderByAscending("Name")
query.whereKey("Name", equalTo: userInfo!["name"]!)
query.getFirstObjectInBackgroundWithBlock {
(object: PFObject?, error: NSError?) -> Void in
if error != nil {
println("The getFirstObject request failed.")
} else {
if let obj = object {
obj.setValue(userInfo!["waitTime"], forKey: "WaitTime")
obj.saveInBackground()
}
println("Successfully retrieved the object.")
}
}

reply(["success": true, "message": "Hello!"])

endBackgroundUpdateTask(taskID)
}
}

对于大量的代码,我深表歉意,但我真的不知道问题出在哪里。

大家有什么想法吗?

最佳答案

将您的 reply() 调用放入“不相关代码”部分。问题是在任何情况下都应该调用 reply() 处理程序,但在您的示例中,如果 pfqueryRequestnil 处理程序永远不会被调用已调用。

关于ios - 未调用handleWatchKitExtensionRequest 的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32571310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com