• iOS 中的一些常用函数


    1.获取 本地语言

    + (NSString *)getLocalLanguage
    {
        NSString *language = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
        return language;
    }

    2.获取mac 地址

    // returns the local MAC address.
    + (NSString*) macAddress:(NSString*)interfaceNameOrNil
    {
        // uses en0 as the default interface name
        NSString* interfaceName = interfaceNameOrNil;
        if (interfaceName == nil)
        {
            interfaceName = @"en0";
        }
        
        int                 mib[6];
        size_t              len;
        char                *buf;
        unsigned char       *ptr;
        struct if_msghdr    *ifm;
        struct sockaddr_dl  *sdl;
        
        mib[0] = CTL_NET;
        mib[1] = AF_ROUTE;
        mib[2] = 0;
        mib[3] = AF_LINK;
        mib[4] = NET_RT_IFLIST;
        
        if ((mib[5] = if_nametoindex([interfaceName UTF8String])) == 0)
        {
            printf("Error: if_nametoindex error
    ");
            return NULL;
        }
        
        if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
        {
            printf("Error: sysctl, take 1
    ");
            return NULL;
        }
        
        if ((buf = malloc(len)) == NULL)
        {
            printf("Could not allocate memory. error!
    ");
            return NULL;
        }
        
        if (sysctl(mib, 6, buf, &len, NULL, 0) < 0)
        {
            printf("Error: sysctl, take 2");
            free(buf);
            return NULL;
        }
        
        ifm = (struct if_msghdr*) buf;
        sdl = (struct sockaddr_dl*) (ifm + 1);
        ptr = (unsigned char*) LLADDR(sdl);
        NSString *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X",
                               *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
        free(buf);
        
        return outstring;
    }

    3.判断是否 越狱

    static const char * __jb_app = NULL;
    
    + (BOOL)isJailBroken
    {
        static const char * __jb_apps[] =
        {
            "/Application/Cydia.app", 
            "/Application/limera1n.app", 
            "/Application/greenpois0n.app", 
            "/Application/blackra1n.app",
            "/Application/blacksn0w.app",
            "/Application/redsn0w.app",
            NULL
        };
    
        __jb_app = NULL;
    
        // method 1
        for ( int i = 0; __jb_apps[i]; ++i )
        {
            if ( [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithUTF8String:__jb_apps[i]]] )
            {
                __jb_app = __jb_apps[i];
                return YES;
            }
        }
        
        // method 2
        if ( [[NSFileManager defaultManager] fileExistsAtPath:@"/private/var/lib/apt/"] )
        {
            return YES;
        }
        
        // method 3
        if ( 0 == system("ls") )
        {
            return YES;
        }
        
        return NO;    
    }
    
    + (NSString *)jailBreaker
    {
        if ( __jb_app )
        {
            return [NSString stringWithUTF8String:__jb_app];
        }
        else
        {
            return @"";
        }
    }
  • 相关阅读:
    node.js学习二---------------------同步API和异步API的区别
    node.js学习一---------------------模块的导入
    ES6函数的特性(箭头语法)
    10分钟了解Android的Handler机制
    10分钟了解Android的事件分发
    SwipeRefreshLayout,用最少的代码定制最美的上下拉刷新样式
    手把手教你React Native 实战之开山篇《一》
    Android 组件化方案探索与思考
    2018谷歌I/O开发者大会8大看点汇总 新品有哪些
    Glide高级详解—缓存与解码复用
  • 原文地址:https://www.cnblogs.com/Seeulater/p/4361796.html
Copyright © 2020-2023  润新知