Files
peko-ios/YuMi/Tools/YYUtility/YYUtility+App.m

156 lines
4.1 KiB
Mathematica
Raw Normal View History

2023-07-06 16:54:13 +08:00
//
// YYUtility+App.m
// YYMobileFramework
//
// Created by wuwei on 14-5-30.
// Copyright (c) 2014 YY Inc. All rights reserved.
//
#import "YYUtility.h"
@implementation YYUtility (App)
2023-07-14 18:50:55 +08:00
+ (id)valueInPlistForKey:(NSString *)key{
2023-07-06 16:54:13 +08:00
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
return [infoDictionary objectForKey:key];
}
+ (NSString *)appVersion{
static NSString *appVersion = nil;
if (!appVersion) {
2023-07-14 18:50:55 +08:00
appVersion = [self valueInPlistForKey:@"CFBundleShortVersionString"];
2023-07-06 16:54:13 +08:00
}
return appVersion;
}
+ (NSString *)appName {
2023-08-09 15:42:15 +08:00
#ifdef DEBUG
2023-11-09 15:26:14 +08:00
NSString *isProduction = [[NSUserDefaults standardUserDefaults]valueForKey:@"kIsProductionEnvironment"];
if([isProduction isEqualToString:@"YES"]){
return @"youmi";
}
2023-08-09 15:42:15 +08:00
NSString *text = [NSString stringWithFormat:@"%@%@%@%@",@"p",@"e",@"k",@"o"];
2023-11-09 15:26:14 +08:00
return text;
2023-08-09 15:42:15 +08:00
#else
return @"youmi";
#endif
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
+ (NSString *)appBuild{
static NSString *appBuild = nil;
if (!appBuild) {
appBuild = [self valueInPlistForKey:(NSString *)kCFBundleVersionKey];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
return appBuild;
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
+ (NSString *)appBundleId{
static NSString *appBundleId = nil;
if (!appBundleId) {
appBundleId = [self valueInPlistForKey:(NSString *)kCFBundleIdentifierKey];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
return appBundleId;
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
+ (NSString *)svnVersion{
static NSString *svnVersion = nil;
if (!svnVersion) {
svnVersion = [self valueInPlistForKey:@"SvnBuildVersion"];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
return svnVersion;
2023-07-06 16:54:13 +08:00
}
static NSString * const kMobileFrameworkResourceBundleName = @"YYMobileFrameworkRes";
2023-07-14 18:50:55 +08:00
+ (NSURL *)URLForMobileFrameworkResourceBundle{
2023-07-06 16:54:13 +08:00
return [[NSBundle mainBundle] URLForResource:kMobileFrameworkResourceBundleName
withExtension:@"bundle"];
}
2023-07-14 18:50:55 +08:00
+ (NSString *)pathForMobileFrameworkResourceBundle{
2023-07-06 16:54:13 +08:00
return [[NSBundle mainBundle] pathForResource:kMobileFrameworkResourceBundleName
ofType:@"bundle"];
}
2023-07-14 18:50:55 +08:00
+ (NSString *)buildType{
2023-07-06 16:54:13 +08:00
#ifdef DEBUG
2023-11-09 15:26:14 +08:00
NSString *isProduction = [[NSUserDefaults standardUserDefaults]valueForKey:@"kIsProductionEnvironment"];
if([isProduction isEqualToString:@"YES"]){
return @"RELEASE";
}
2023-07-06 16:54:13 +08:00
return @"DEBUG";
#else
return @"RELEASE";
#endif
}
2023-07-14 18:50:55 +08:00
+ (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)fileURL{
2023-07-06 16:54:13 +08:00
if (![[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
NSLog(@"File %@ dosen't exist!", fileURL);
return NO;
}
NSError *error = nil;
BOOL result = [fileURL setResourceValue:[NSNumber numberWithBool:YES]
forKey:NSURLIsExcludedFromBackupKey
error:&error];
if (!result) {
NSLog(@"Error excluding '%@' from backup, error: %@.", fileURL, error);
}
return result;
}
static NSString *_from = nil;
2023-07-14 18:50:55 +08:00
+ (NSString *)getAppSource{
2023-07-06 16:54:13 +08:00
if (_from == nil) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"sourceid.dat" ofType:nil];
NSError *error;
NSString *from = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
2023-07-14 18:50:55 +08:00
//
2023-07-06 16:54:13 +08:00
if (from) {
2023-07-14 18:50:55 +08:00
from = [self removeSpaceAndNewline:from];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
// 0
2023-07-06 16:54:13 +08:00
if (!error
&& ![from isEqualToString:@"0"]
&& ![from isEqualToString:@""]) {
_from = from;
} else {
2023-09-15 17:07:24 +08:00
if (isEnterprise == NO) {
_from = @"piko_Enterprise"; //
}else {
2023-11-03 11:19:14 +08:00
_from = PI_App_Source; // App Store
2023-09-15 17:07:24 +08:00
}
2023-07-06 16:54:13 +08:00
}
}
return _from;
}
2023-07-14 18:50:55 +08:00
+ (BOOL)isFromAppStore{
if([[[YYUtility getAppSource] lowercaseString] isEqualToString:@"appstore"]){
2023-07-06 16:54:13 +08:00
return YES;
}
return NO;
}
2023-07-14 18:50:55 +08:00
+ (NSString *)removeSpaceAndNewline:(NSString *)str{
2023-07-06 16:54:13 +08:00
NSString *temp = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
temp = [temp stringByReplacingOccurrencesOfString:@"\r" withString:@""];
temp = [temp stringByReplacingOccurrencesOfString:@"\n" withString:@""];
return temp;
}
@end