swift之获取APP各种参数和device参数、获取APPstore信息、以及跳转到appstore

============app信息和device信息==========

//获取appstore信息、获取app信息、获取手机设备信息

import UIKit

class LYBGetAppinfoExtention: NSObject {

}
extension String{
    
    //下载页、详情页面、评论页面的地址---如果不起效果:将 http:// 替换为 itms:// 或者 itms-apps://,注意用真机才有效果
    static func gotoappstoreDetailAndStars(){
    
       let urs="itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=1123550373"
       let url:URL?=URL.init(string: urs)
        UIApplication.shared.open(url!, options:[:]) { (success) in
            
        }
    }
    
     //下载页,评分页---如果不起效果:将 http:// 替换为 itms:// 或者 itms-apps://,注意用真机才有效果
    static  func  gotoappstoreStarandDownload(){
      let urs="https://itunes.apple.com/app/id1123550373"
      let url:URL?=URL.init(string: urs)
        UIApplication.shared.open(url!, options:[:]) { (success) in
            
        }
    }
    
     //下载页,评分页---如果不起效果:将 http:// 替换为 itms:// 或者 itms-apps://,注意用真机才有效果
    static func lookappstore(){
        let urs="itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=1123550373"
        let url:URL?=URL.init(string: urs)
        UIApplication.shared.open(url!, options:[:]) { (success) in
            
        }
    }
    
    
    //    ===============获取appstore中应用的信息========
    /*调用
     let s = String.getAppStoreInfo() as! [Any]  //返回的是一个数组,数组包含字典
     let ss = s[0] as![String:Any] //数组只有一个元素,这个元素就是字典
     print("\(String(describing: ss["version"]))")
     
     */
    
    static   func getAppStoreInfo() ->Any{

//    要么改成https,
//    要么info.plist加NSAppTransportSecurity.NSAllowsArbitraryLoads = true,
//    获取信息的地址:

    let appidStr:String="1123550373"

    let appurlStr:String=String.init(format: "https://itunes.apple.com/cn/lookup?id=%@", appidStr)

    let url:URL=URL.init(string: appurlStr)!

    do{

       let jsonData=try Data.init(contentsOf: url)

       let json=try JSONSerialization.jsonObject(with: jsonData, options: []) as! [String:Any]

       let res=json["results"]//APPstore信息
//       print("\(String(describing: res))")
        return res as Any
      }catch{
        return ""
      }
    }
    
    //============获取app信息==============
    static    func getInfodict()->[String:Any]{
        let infoDic = Bundle.main.infoDictionary
        return infoDic!
    }
    //获取app名字
    static  func getappName(){
         let appName: String = (Bundle.main.object(forInfoDictionaryKey: "CFBundleName")as!String?)!
        Swift.print("\(appName)")
    }
    
    static  func getappbundId()->String{
         //bundleID
     let bundId:String=Bundle.main.bundleIdentifier!
        Swift.print("\(bundId)")
        return  bundId
    }
    
    static  func getappVersion()->String{
    // 获取App的版本号---version(上线的版本号)
      let infoDic=getInfodict()
        let appVersion:String = infoDic["CFBundleShortVersionString"]! as! String
        Swift.print("\(appVersion)")
        return appVersion
    }
    
    static   func getappBuildVersion()->String{
  // 获取App的build版本
        let infoDic=getInfodict()
     let appBuildVersion:String = infoDic["CFBundleVersion"]! as! String
        Swift.print("\(appBuildVersion)")
        return appBuildVersion
    }
    
    static   func getappNames()->String{
 // 获取App的名称
        let infoDic=getInfodict()
     let appNames :String = infoDic["CFBundleName"]! as! String
        Swift.print("\(appNames)")
        return appNames
    }
    
    static  func getappDispaleyname()->String{
 // app名称name,当displayname存在时,name显示为override,displayname不存在时,name正常显示
        let infoDic=getInfodict()
     let appDispaleyname:String  = infoDic["CFBundleDisplayName"]! as! String
        print("\(appDispaleyname)")
     return appDispaleyname
    }
     
    //============获取手机设备信息==============
    static  func getidentifierNumber()->String{
     //手机序列号(唯一标识)
     let  identifierNumber:String  = (UIDevice.current.identifierForVendor?.uuidString)!
     return identifierNumber
    }
    
    static  func getuserPhoneName()->String{
     //手机别名:用户定义的名称
      let  userPhoneName:String  = UIDevice.current.name
        return userPhoneName
    }
    
    static  func getdeviceName()->String{
     //设备名称
      let deviceName:String  = UIDevice.current.systemName
    return deviceName
    }
    
    static  func getphoneVersion()->String{
      //手机系统版本
      let phoneVersion:String  = UIDevice.current.systemVersion
        return phoneVersion
    }
    
    static  func getphoneModel()->String{
    //手机型号
    let phoneModel:String  = UIDevice.current.model
     return phoneModel
    }
    
    static   func getlocalPhoneModel()->String{
     //地方型号 (国际化区域名称)
     let localPhoneModel:String  = UIDevice.current.localizedModel
     return localPhoneModel
     }
     
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值