嗨,我是swift 3和Xcode 8的新手我有一个问题,我的facebook分享选项,初始文本内容在我的模拟器中工作正常,显示facebook post弹出内容,但没有在我的设备上显示内容facebook post pop-up
import UIKit
import Social
import FBSDKLoginKit
import CoreData
class ViewControllerGame: UIViewController {
var seconds = 30
var timer = Timer()
var cur = 0;
var d = 0;
var someValue: Int = 0 {
didSet {
scoreLabel.text = "\(someValue)"
}
}
@IBOutlet weak var tapHere: UIButton!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var scoreLabel: UILabel!
@IBAction func logoutButton(_ sender: Any) {
FBSDKLoginManager().logOut()
}
@IBAction func highScoreBtn(_ sender: Any) {
highscore()
}
func highscoreAlertView(title:String, message:String){
let highscorealert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
highscorealert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: { (action) in
highscorealert.dismiss(animated: true, completion: nil)
}))
self.present(highscorealert, animated: true, completion: nil)
}
@IBAction func tapHere(_ sender: UIButton) {
someValue += 1
d = self.someValue
}
@IBOutlet weak var sliderOutlet: UISlider!
@IBOutlet weak var startOutlet: UIButton!
@IBAction func start(_ sender: AnyObject)
{
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(ViewControllerGame.counter), userInfo: nil, repeats: true)
startOutlet.isHidden = true
tapHere.isHidden = false
scoreLabel.isHidden = false
}
func highscore(){
let appDelegate = (UIApplication.shared.delegate) as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let score = ScoreList(context:context)
score.newScore = Int32(self.someValue)
appDelegate.saveContext()
do {
let result = try context.fetch(ScoreList.fetchRequest())
let scores = result as! [ScoreList]
for score in scores {
print("Scores: \(score.newScore)")
}
let f = scores.sorted(by: {$0.newScore > $1.newScore })
print("Here:\(f)")
/* if let scoreArray = f as? NSDictionary{
let scoreArr=(scoreArray["newScore"] as? Int32)
print("asdf:\(scoreArr!)")
}
else{
print("asdasdfsdf")
}
*/
} catch {
print("Error")
}
highscoreAlertView(title: "HIGHSCORES", message:"")
}
func counter()
{
if(self.seconds != 0){
seconds -= 1
label.text = String(format: "%02d", self.seconds % 60 )
}
if (seconds == 0)
{
timer.invalidate()
self.label.text = "00"
createAlert(title: "Your Score is", message: "\(self.someValue)")
self.seconds = 30
}
}
@IBAction func shareButton(_ sender: Any) {
let shareToFacebook : SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
shareToFacebook.setInitialText("Timer Game score is \(d)")
self.present(shareToFacebook, animated: true, completion: nil)
self.commonthing()
}
func createAlert (title:String, message:String)
{
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "RETRY", style: UIAlertActionStyle.default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
self.commonthing()
}))
alert.addAction(UIAlertAction(title: "SHARE", style: UIAlertActionStyle.default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
let shareToFacebook : SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
shareToFacebook.setInitialText("Timer Game score is \(self.d)")
self.present(shareToFacebook, animated: true, completion: nil)
self.commonthing()
}))
self.present(alert, animated: true, completion: nil)
}
func commonthing(){
self.seconds = 30
self.label.text = "30"
self.viewDidLoad()
}
override func viewDidLoad()
{
super.viewDidLoad()
someValue = 0
self.seconds = 30
tapHere.isHidden = true
scoreLabel.isHidden = true
startOutlet.isHidden = false
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}