我根本无法理解为什么Facebook和Twitter按钮没有打开?
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let location = touch.locationInNode(self)
// Reviews & Rating
let reviewsAppString = "itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APP_ID"
let reviewsApp = NSURL(string: reviewsAppString)
let reviewsWebString = "https://itunes.apple.com/us/developer/DEVELOPER_NAME/DEVELOPER_ID"
let reviewsWeb = NSURL(string: reviewsWebString)
// Facebook
let fbWebString = "https://www.facebook.com/PAGE_NAME"
let fbWeb = NSURL(string: fbWebString)
let fbAppString = "fb://profile/PAGE_ID"
let fbApp = NSURL(string: fbAppString)
// Twitter
let twWebString = "https://twitter.com/USER_NAME"
let twWeb = NSURL(string: twWebString)
let twAppString = "twitter://user?screen_name=USER_ID"
let twApp = NSURL(string: twAppString)
if nodeAtPoint(location) == gameCenterButton {
NSNotificationCenter.defaultCenter().postNotificationName("showLeaderboard", object: nil)
}
else if nodeAtPoint(location) == playButton {
presentScene(GameScene())
}
else if nodeAtPoint(location) == soundButton {
toggleSound()
}
// REVIEWS AND RATINGS
else if nodeAtPoint(location) == rateButton {
if (UIApplication.sharedApplication().canOpenURL(reviewsApp!)) {
UIApplication.sharedApplication().openURL(reviewsApp!)
}
else {
if UIApplication.sharedApplication().canOpenURL(reviewsWeb!) {
UIApplication.sharedApplication().openURL(reviewsWeb!)
}
// FACEBOOK
else if nodeAtPoint(location) == facebookButton {
if (UIApplication.sharedApplication().canOpenURL(fbApp!)) {
UIApplication.sharedApplication().openURL(fbApp!)
}
else {
if UIApplication.sharedApplication().canOpenURL(fbWeb!) {
UIApplication.sharedApplication().openURL(fbWeb!)
}
// TWITTER
else if nodeAtPoint(location) == twitterButton {
if (UIApplication.sharedApplication().canOpenURL(twApp!)) {
UIApplication.sharedApplication().openURL(twApp!)
}
else {
if UIApplication.sharedApplication().canOpenURL(twWeb!) {
UIApplication.sharedApplication().openURL(twWeb!)
}
我只能认为我使用了太多其他if语句并且有更好/更清晰的方法来做,但我很难过!
Xcode 7.3.1 - Swift 2.2