ios获取项目app名称_ios获取app名称 - CSDN
  • 有时候在项目中需要知道当前APP的版本号,项目名称,APP名称,系统版本等信息,这里简单介绍几种方法: 1. 从NSBundle类的infoDictionary中获取,代码如下: //获取所有信息字典 NSDictionary *infoDictionary = [...

    有时候在项目中需要知道当前APP的版本号,项目名称,APP名称,系统版本等信息,这里简单介绍几种方法:


    1. 从NSBundle类的infoDictionary中获取,代码如下:

    //获取所有信息字典
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        
        //    NSLog(@"%@",infoDictionary);
        //    CFShow((__bridge CFTypeRef)(infoDictionary));
        
        NSString *executableFile = [infoDictionary objectForKey:(NSString *)kCFBundleExecutableKey]; //获取项目名称
        
        NSLog(@"executableFile == %@",executableFile);
        
        NSString *version = [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]; //获取项目版本号
        NSLog(@"version .. %@",version);
        
        // app名称
        NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
        NSLog(@"app_Name == %@",app_Name);
        
        // app版本
        NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
        NSLog(@"app_Version .. %@",app_Version);
        // app build版本
        NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
        NSLog(@"app_build >> %@",app_build);
    输出:

    2016-03-11 14:40:42.396 PhotosDemo[1930:168508] executableFile == PhotosDemo
    2016-03-11 14:40:42.396 PhotosDemo[1930:168508] version .. 1
    2016-03-11 14:40:42.396 PhotosDemo[1930:168508] app_Name == 测试
    2016-03-11 14:40:42.397 PhotosDemo[1930:168508] app_Version .. 1.0
    2016-03-11 14:40:42.397 PhotosDemo[1930:168508] app_build >> 1
    具体字典中还有哪些key值,可打印输出后查看,获取所需信息;


    2. 使用NSBundle的实例方法objectForInfoDictionaryKey

     NSBundle *mainBundle = [NSBundle mainBundle];
        
        //项目名称
        NSString *executableFile = [mainBundle objectForInfoDictionaryKey:(NSString*)kCFBundleExecutableKey];
        NSLog(@"%@",executableFile);
        
        //版本号
        NSString *version = [mainBundle objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey];
        NSLog(@"%@",version);
        
        //bundleID
        NSString *bundleID = [mainBundle objectForInfoDictionaryKey:(NSString*)kCFBundleIdentifierKey];
        NSLog(@"%@",bundleID);
        
        //开发语言环境
        NSString *lon = [mainBundle objectForInfoDictionaryKey:(NSString*)kCFBundleDevelopmentRegionKey];
        NSLog(@"%@",lon);
        
        //名称
        NSString *name = [mainBundle objectForInfoDictionaryKey:(NSString*)kCFBundleNameKey];
        NSLog(@"%@",name);
        
        NSString *appName = [mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
        NSLog(@"%@",appName);
    

    输出:

    2016-03-11 14:42:58.076 PhotosDemo[1945:170139] PhotosDemo
    2016-03-11 14:42:58.077 PhotosDemo[1945:170139] 1
    2016-03-11 14:42:58.077 PhotosDemo[1945:170139] com.artup.PhotosDemo
    2016-03-11 14:42:58.077 PhotosDemo[1945:170139] en
    2016-03-11 14:42:58.077 PhotosDemo[1945:170139] PhotosDemo
    2016-03-11 14:42:58.077 PhotosDemo[1945:170139] 测试
    

    3.系统中还有一个访问这些属性的方法CFBundleGetVersionNumber(),CFBundleGetIdentifier()等方法,他们的参数都是CFBundleRef类型的,这个参数从哪获得,确实废了些劲,网上也没找到合适介绍,在翻底层的时候无意间发现CFBundleRef CFBundleGetMainBundle(void);这个函数,参数为空,返回一个CFBundleRef;

    使用方式如下:

    //获取CFBundleRef
        CFBundleRef ref = CFBundleGetMainBundle();
        
        //获取属性字典 同 [[NSBundle mainBundle] infoDictionary]
        NSDictionary *infoDictionary = (NSDictionary*)CFBundleGetInfoDictionary(ref);
        NSLog(@"%@",infoDictionary);
        
        //这个数目比较大,不是我们设置的版本号,在上面的infoDictionary字典中有这个值
        UInt32 versionNumber = CFBundleGetVersionNumber(ref);
        NSLog(@"%ld",(long)versionNumber);
        
        //获取标示符,就是Bundle ID
        NSString *bundleID = (NSString*)CFBundleGetIdentifier(ref);
        NSLog(@"%@",bundleID);
    

    输出:

    2016-03-11 14:44:35.150 PhotosDemo[1956:171246] {
        BuildMachineOSBuild = 15D21;
        CFBundleDevelopmentRegion = en;
        CFBundleDisplayName = "\U6d4b\U8bd5";
        CFBundleExecutable = PhotosDemo;
        CFBundleIdentifier = "com.artup.PhotosDemo";
        CFBundleInfoDictionaryVersion = "6.0";
        CFBundleInfoPlistURL = "Info.plist -- file:///Users/mac/Library/Developer/CoreSimulator/Devices/5A7E314D-EC55-4560-A787-BCB1941AE23A/data/Containers/Bundle/Application/0322A01C-45F8-4F60-83FD-B15F30D909F1/PhotosDemo.app/";
        CFBundleName = PhotosDemo;
        CFBundleNumericVersion = 16809984;
        CFBundlePackageType = APPL;
        CFBundleShortVersionString = "1.0";
        CFBundleSignature = "????";
        CFBundleSupportedPlatforms =     (
            iPhoneSimulator
        );
        CFBundleVersion = 1;
        DTCompiler = "com.apple.compilers.llvm.clang.1_0";
        DTPlatformBuild = "";
        DTPlatformName = iphonesimulator;
        DTPlatformVersion = "9.2";
        DTSDKBuild = 13C75;
        DTSDKName = "iphonesimulator9.2";
        DTXcode = 0720;
        DTXcodeBuild = 7C68;
        LSRequiresIPhoneOS = 1;
        MinimumOSVersion = "9.2";
        UIDeviceFamily =     (
            1,
            2
        );
        UILaunchStoryboardName = LaunchScreen;
        UIMainStoryboardFile = Main;
        UIRequiredDeviceCapabilities =     (
            armv7
        );
        UISupportedInterfaceOrientations =     (
            UIInterfaceOrientationPortrait,
            UIInterfaceOrientationLandscapeLeft,
            UIInterfaceOrientationLandscapeRight
        );
    }
    2016-03-11 14:44:35.150 PhotosDemo[1956:171246] 16809984
    2016-03-11 14:44:35.150 PhotosDemo[1956:171246] com.artup.PhotosDemo
    

    另外,系统中预定义了几个常用key:

    CF_EXPORT
        const CFStringRef kCFBundleInfoDictionaryVersionKey;
        /* The version of the Info.plist format */
        //Info.plist 文件版本
        
        CF_EXPORT
        const CFStringRef kCFBundleExecutableKey;
        /* The name of the executable in this bundle, if any */
        //可用的项目名称
        
        CF_EXPORT
        const CFStringRef kCFBundleIdentifierKey;
        /* The bundle identifier (for CFBundleGetBundleWithIdentifier()) */
        //项目的bundle identifier
        
        CF_EXPORT
        const CFStringRef kCFBundleVersionKey;
        /* The version number of the bundle.  For Mac OS 9 style version numbers (for example "2.5.3d5"), */
        /* clients can use CFBundleGetVersionNumber() instead of accessing this key directly since that */
        /* function will properly convert the version string into its compact integer representation. */
        //
        CF_EXPORT
        const CFStringRef kCFBundleDevelopmentRegionKey;
        /* The name of the development language of the bundle. */
        //语言环境
        
        CF_EXPORT
        const CFStringRef kCFBundleNameKey;
        /* The human-readable name of the bundle.  This key is often found in the InfoPlist.strings since it is usually localized. */
        
        CF_EXPORT
        const CFStringRef kCFBundleLocalizationsKey;
        /* Allows an unbundled application that handles localization itself to specify which localizations it has available. */
    


    以上只是列举了部分的信息,还有很多信息可以使用相同的方式获取...

    展开全文
  • //联系人:石虎 QQ:1224614774 昵称:嗡嘛呢叭咪哄 /**  1.图形显示  2.代码实现  3.下载 demo  */ 一、图形展示 图1: 图2: 二、代码实现 // // ViewController.m ...// Cr

    //联系人:石虎 QQ:1224614774 昵称:嗡嘛呢叭咪哄

    /**

     1.图形显示

     2.代码实现

     3.下载 demo

     */

    一、图形展示

    1:


    2:


    二、代码实现


    //

    //  ViewController.m

    //  自动增减算法

    //

    //  Created by 石虎 on 2017/9/29.

    //  Copyright © 2017年 石虎. All rights reserved.

    //


    #import "ViewController.h"


    @interface ViewController ()


    @end

    /** 获取APP名称 */

    #define APP_NAME ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"])

    /** 程序版本号 */

    #define APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

    /** 获取APP build版本 */

    #define APP_BUILD ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"])

    /** User-Agent */

    #define APP_USER_AGENT [NSString stringWithFormat:@"石虎/%@ (%@;U;%@ %@;%@/%@)", \

    APP_VERSION, DeviceModel, DeviceSystemName, DeviceVersion, DeviceLocal, DeviceLang]



    @implementation ViewController


    - (void)viewDidLoad {

        [super viewDidLoad];

        NSLog(@"获取APP名称 === %@,程序版本号===,%@,获取APP build版本==,%@",APP_NAME,APP_VERSION,APP_BUILD);

    }

    @end


    三、打印结果

    打印: 2017-10-0915:05:03.296 自动增减算法[44032:2027891] 获取APP名称 === shihu ,程序版本号===,1.0.2,获取APP build版本==,12345


    四、下载 demo 链接


      请联系本人,代码会发布在 GitHub 或者是码云上;


    谢谢!!!


    展开全文
  • NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];...// app名称   NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];   // app
    1. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];  
    2.  CFShow(infoDictionary);  
    3. // app名称  
    4.  NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];  
    5.  // app版本  
    6.  NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];  
    7.  // app build版本  
    8.  NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];  
    9.   
    10.   
    11.       
    12.     //手机序列号  
    13.     NSString* identifierNumber = [[UIDevice currentDevice] uniqueIdentifier];  
    14.     NSLog(@"手机序列号: %@",identifierNumber);  
    15.     //手机别名: 用户定义的名称  
    16.     NSString* userPhoneName = [[UIDevice currentDevice] name];  
    17.     NSLog(@"手机别名: %@", userPhoneName);  
    18.     //设备名称  
    19.     NSString* deviceName = [[UIDevice currentDevice] systemName];  
    20.     NSLog(@"设备名称: %@",deviceName );  
    21.     //手机系统版本  
    22.     NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];  
    23.     NSLog(@"手机系统版本: %@", phoneVersion);  
    24.     //手机型号  
    25.     NSString* phoneModel = [[UIDevice currentDevice] model];  
    26.     NSLog(@"手机型号: %@",phoneModel );  
    27.     //地方型号  (国际化区域名称)  
    28.     NSString* localPhoneModel = [[UIDevice currentDevice] localizedModel];  
    29.     NSLog(@"国际化区域名称: %@",localPhoneModel );  
    30.       
    31.     NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];  
    32.     // 当前应用名称  
    33.     NSString *appCurName = [infoDictionary objectForKey:@"CFBundleDisplayName"];  
    34.     NSLog(@"当前应用名称:%@",appCurName);  
    35.     // 当前应用软件版本  比如:1.0.1  
    36.     NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];  
    37.     NSLog(@"当前应用软件版本:%@",appCurVersion);  
    38.     // 当前应用版本号码   int类型  
    39.     NSString *appCurVersionNum = [infoDictionary objectForKey:@"CFBundleVersion"];  
    40.     NSLog(@"当前应用版本号码:%@",appCurVersionNum); 
    展开全文
  • //获取所有信息字典 NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; ...NSString *executableFile = [infoDictionary ...objectForKey:(NSString *)kCFBundleExecutableKey...//获取项目名称

    //获取所有信息字典

    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

    NSString *executableFile = [infoDictionary objectForKey:(NSString *)kCFBundleExecutableKey]; //获取项目名称


    NSLog(@"executableFile == %@",executableFile);


    NSString *version = [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]; //获取项目版本号

    NSLog(@"version .. %@",version);


    // app名称

    NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];

    NSLog(@"app_Name == %@",app_Name);


    // app版本

    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];

    NSLog(@"app_Version .. %@",app_Version);

    // app build版本

    NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];

    NSLog(@"app_build >> %@",app_build);


    展开全文
  • let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String let appName = Bundle.main.infoDictionary!["CFBundleDisplayName"] as!...链接: iOS 获取当前app名称和版本号 ...
  • // 获取当前App的基本信息字典   NSDictionary *infoDictionary = [[NSBundle ... //app名称   NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];   // app版本 
  • NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDictionary);...// app名称 NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"]; // app版本
  • NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDictionary);... // app名称 NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
  • 获取App的版本号、App的build版本号、包名、App显示名称等等 /*获取当前App的版本号信息*/ + (NSString *)getAppVersion { NSBundle *currentBundle = [NSBundle mainBundle]; NSDictionary *infoDictionary = ...
  • 开发项目过程中,经常会遇到版本迭代更新,获取项目版本号等问题,这些情况都...一、获取App名称 要想获取App名称,首先要在Xcode—>General—>Identity—>Display Name,给项目设置好名...
  • NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSString *appName = [bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
  • Class c =NSClassFromString(@"LSApplicationWorkspace");   id s = [(id)c performSelector:NSSelectorFromString(@"defaultWorkspace")];   NSArray *array = [s performSelector:NSSelectorFromString(@
  • 1.app尺寸,去掉状态栏 CGRect r = [ UIScreen mainScreen ].applicationFrame; r=0,20,320,460 2.屏幕尺寸 CGRect rx = [ UIScreen mainScreen ].bounds; r=0,0,320,480  3.状态栏...
  • 为什么要获取App资源? 真实开发中,实现一个App里面会用到各种图片资源(包括图标、背景图片等等),这些资源通常是美工提供给我们,我们直接使用即可。但是,如果我们想要模仿一个App,也没有真正的美工人员提供给...
  • App在处理网络资源时,一般都会做离线缓存处理,其中最典型离线缓存框架为SDWebImage。 但是,离线缓存会占用一定的存储空间,所以缓存清理功能基本成为资讯、购物、阅读类app的标配功能。 下面用代码来分别介绍...
  • NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];...// app名称   NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];   // app
  • NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];...// app名称NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];// app版本NSString *app_Ve
  • 获取AppStore中App的相关信息:  使用蒲公英发布包的时候,我们如果查看应用信息,会看到和应用显示在AppStore上类似的介绍;  这些信息我们自己也可以通过请求进行获取;   我们使用了Get方式:   ...
  • iOS 获取wifi ssid 名称

    2013-11-28 15:09:14
    SSID全称Service Set IDentifier, 即Wifi网络...在IOS 4.1以上版本提供了公开的方法来获取该信息. [html] view plaincopy #import SystemConfiguration/CaptiveNetwork.h>  [html] view plaincop
1 2 3 4 5 ... 20
收藏数 27,158
精华内容 10,863
关键字:

ios获取项目app名称