跳转到设置页面 与appstory

时间:2023-03-10 01:56:19
跳转到设置页面 与appstory

//MARK:系统跳到应用设置页面

func systemMySet(){

let url = NSURL(string: UIApplicationOpenSettingsURLString)

if let url = url where UIApplication.sharedApplication().canOpenURL(url) {

UIApplication.sharedApplication().openURL(url)

}

}

//跳转到系统设置的其他界面需要 在项目中的info中添加 URL types 添加 URL Schemes 为 prefs的url

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];

//MARK:跳转到appstory

func appStory(){

//let url = "http://itunes.apple.com/lookup?id=1125895585"//只在国内的需要加cn

let url = "http://itunes.apple.com/cn/lookup?id=1125895585"

Prequest.requestJSON(.POST, URLString: url, completion: { (response) in

// pprintLog("response:\(response)")

let result = (response?.objectForKey("results"))! as! NSArray

pprintLog("result:\(result)")

let dic = (result.lastObject)! as! NSDictionary

let lineversion = dic.objectForKey("version") as! String

let infoDictionary = NSBundle.mainBundle().infoDictionary

let localVersion : String? = infoDictionary! ["CFBundleVersion"] as? String

if localVersion != lineversion{

let alert = UIAlertController(title: "版本更新", message: "检测到有新版本,前往appstory更新", preferredStyle: UIAlertControllerStyle.Alert)

alert.addAction(UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel) { (UIAlertAction) -> Void in

})

alert.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.Default) { (UIAlertAction) -> Void in

//然后将 http:// 替换为 itms:// 或者 itms-apps://:

UIApplication.sharedApplication().openURL(NSURL(string: "http://iTunes.Apple.com/us/app/appid")!)

})

self.presentViewController(alert, animated: true, completion: nil)

}

}) { (failed) in

pprintLog("failed:\(failed)")

}

}

//跳转到app评论页

func appStoryComment(){

let alert = UIAlertController(title: "评价应用", message: "立刻前往appstory评价", preferredStyle: UIAlertControllerStyle.Alert)

alert.addAction(UIAlertAction(title: "稍后", style: UIAlertActionStyle.Cancel) { (UIAlertAction) -> Void in

})

alert.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.Default) { (UIAlertAction) -> Void in

let url = NSURL.init(string: "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=appid&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8")

UIApplication.sharedApplication().openURL(url!)

})

self.presentViewController(alert, animated: true, completion: nil)

}