美文网首页
几个常用的功能

几个常用的功能

作者: Luy7788 | 来源:发表于2016-09-22 22:47 被阅读25次

点击跳转到AppStore给应用评分功能

/**
 *  跳转到AppStore给应用评分
 *
 *  @param appId APP ID
 */
+ (void)toAppStoreReview:(NSString *)appId
{
    NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@",appId];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

点击跳转到AppStore下载应用功能

/**
 *  跳转到AppStore下载应用
 *
 *  @param appId APP ID
 */
+ (void)toAppStoreDownload:(NSString *)appId
{
    NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@",appId];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

调用系统拨打电话

/**
 *  调用系统拨打电话
 *
 *  @param phoneNumber 电话号码
 */
+ (void)callTelephone:(NSString *)phoneNumber
{
    NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNumber]];
    UIWebView *callWebview = [[UIWebView alloc] initWithFrame:CGRectZero];
    [callWebview loadRequest:[NSURLRequest requestWithURL:phoneURL]];
    [[[UIApplication sharedApplication]keyWindow] addSubview:callWebview];
}

清除缓存功能

/**
 *  获取缓存文件大小,用来清理缓存
 *
 *  @return 返回缓存大小 MB(兆)
 */
+ (float)cachesFileSize
{
    NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0];
    
    NSFileManager *manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:cachPath]) return 0.0;
    
    NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:cachPath] objectEnumerator];
    NSString *fileName;
    long long folderSize = 0;
    while ((fileName = [childFilesEnumerator nextObject]) != nil)
    {
        NSString *fileAbsolutePath = [cachPath stringByAppendingPathComponent:fileName];
        if ([manager fileExistsAtPath:fileAbsolutePath])
        {
            folderSize += [[manager attributesOfItemAtPath:fileAbsolutePath error:nil] fileSize];
        }
    }
    return folderSize / (1024.0 * 1024.0);
}
 
/**
 *  清理NSCachesDirectory缓存
 *
 *  @param needAsync 是否需要异步清除
 */
+ (void)clearCaches:(BOOL)needAsync
{
    if (needAsync) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
            NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
            for (NSString *p in files) {
                NSError *error;
                NSString *path = [cachPath stringByAppendingPathComponent:p];
                if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
                    [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
                }
            }
        });
    }else{
        NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
        for (NSString *p in files) {
            NSError *error;
            NSString *path = [cachPath stringByAppendingPathComponent:p];
            if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
                [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
            }
        }
    }
}

获取APP应用名称

/**
 *  获取APP应用名称
 *
 *  @return APP应用名称
 */
+ (NSString *)getAppName
{
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *appName = [infoDic objectForKey:@"CFBundleDisplayName"];
    return appName;
}

获取当前设备iOS系统版本

+ (NSString *)getIOSVersion
{
    return [[UIDevice currentDevice] systemVersion];
}

获取APP版本号Version

/**
 *  获取APP版本号Version 第一个整数代表重大修改的版本,如实现新的功能或重大变化的修订。第二个整数表示的修订,实现较突出的特点。第三个整数代表维护版本
 *
 *  @return 发布版本号 如当前上架版本为1.1.0  之后你更新的时候可以改为1.1.1
 */
+ (NSString *)getAppVersion
{
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *appVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    return appVersion;
}

获取APP开发版本号Build版本

/**
 *  获取APP开发版本号Build
 *
 *  @return  内部标示,用以记录开发版本的,每次更新的时候都需要比上一次高
 */
+ (NSString *)getAppBuildVersion
{
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *appBuild = [infoDic objectForKey:@"CFBundleVersion"];
    return appBuild;
}

获取APP Bundle Id

/**
 *  获取APP Bundle Id
 *
 *  @return com.company.appName
 */
+ (NSString *)getAppBundleId
{
    return [[NSBundle mainBundle] bundleIdentifier];
}

判断是否第一次使用该版本app

/**
 *  判断是否第一次使用该版本app
 *
 *  @param application AppDelegate的didFinishLaunchingWithOptions:方法的application
 *
 *  @return 返回是否是第一次启动YES:是 | NO:不是
 */
+ (BOOL)isFirstUsed:(UIApplication *)application
{
    // 1.从Info.plist中取出版本号
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *version = [NSString stringWithFormat:@"%@(%@)", infoDic[@"CFBundleShortVersionString"], infoDic[@"CFBundleVersion"]];
    // 2.从沙盒中取出上次存储的版本号
    NSString *saveVersion = [[NSUserDefaults standardUserDefaults] objectForKey:@"SJSystemVersion"];
    
    if ([version isEqualToString:saveVersion]) { // 不是第一次使用这个版本
        // 显示状态栏
        application.statusBarHidden = NO;
        // 直接进入启动页
        return NO;
    } else { // 版本号不一样:第一次使用新版本
        // 将新版本号写入沙盒
        [[NSUserDefaults standardUserDefaults] setObject:version forKey:@"SJSystemVersion"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        
        // 显示版本新特性界面
        return YES;
    }
}

userDefault

/**
 *  保存信息到userDefault种
 *
 *  @param obj 保存的对象
 *  @param key 对应的key
 *
 *  @return 成功与否
 */
+(BOOL)userDefaultSaveWithObject:(id)obj Key:(NSString *)key{
    
    [[NSUserDefaults standardUserDefaults] setObject:obj forKey:key];
    BOOL isSuccess = [[NSUserDefaults standardUserDefaults] synchronize];
    return isSuccess;
}

/**
 *  从userDefault读取关键字key的obj
 *
 *  @param key 对应的key
 *
 */
+(id)userDefaultReadWithKey:(NSString *)key{
    
    return [[NSUserDefaults standardUserDefaults] objectForKey:key];
}

相关文章

  • 几个常用的功能

    点击跳转到AppStore给应用评分功能 点击跳转到AppStore下载应用功能 调用系统拨打电话 清除缓存功能 ...

  • Toodledo常用到的几个功能

    记得使用Wunderlist时的那些日子 我曾有大概两年的时间使用Wunderlist来管理我的事务,它漂亮灵巧,...

  • Gulp的几个常用功能

    npm 安装 Gulp 常用方法 gulp.task -- 定义任务 gulp.src -- 找到需要执行任务的文...

  • redis几个简单命令

    查看是否运行 启动 停止 redisUtil几个常用功能

  • 微信几个不常用的功能

    不常用但是会用得到的功能 1. 发布盆友圈时候的分组可见 2. 拉人进群,来验证对方是否删除了你 如果对方没你好友...

  • 风光摄影拍摄及后期

    1.手机风光拍摄常用的摄影功能。 2.提升风光照层次感的几个技巧。 3.风光修图思路分析。 常用功能 1.大儿砸的...

  • Excel表格插件运用

    Excel表格插件运用 推荐使用“KUTOOLS”,已经集成超多实用扩充功能。这里只介绍我常用的几个功能,更多的请...

  • Charles for Mac使用

    Charles的功能很强大,我们这里只介绍几个常用的并且非常实用的功能: 将Charles设置成系统代理 截取移动...

  • ExpandableListView使用时几个常用功能

    第一次写文章,一方面为了分享下自己项目中遇到的一些常见问题,记录下来方便以后回头看看,另一方面也是想看下大家有没有...

  • 自动化工具

    Postman功能更完整,也更合适用于团队合作开发,以下是整理的几个重要常用功能,但是功能远不止这些。 创建Htt...

网友评论

      本文标题:几个常用的功能

      本文链接:https://www.haomeiwen.com/subject/cuxtyttx.html