使用Xcode创建plist文件和使用

  1.  //读取plist  

  2.   

  3.     NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"plistdemo" ofType:@"plist"];  

  4.     NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];  

  5.     NSLog(@"%@", data);  

  6.       

  7.     //添加一项内容  

  8.     [data setObject:@"add some content" forKey:@"c_key"];  

  9.       

  10.     //获取应用程序沙盒的Documents目录  

  11.     NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);  

  12.     NSString *plistPath1 = [paths objectAtIndex:0];  

  13.       

  14.     //得到完整的文件名  

  15.     NSString *filename=[plistPath1 stringByAppendingPathComponent:@"test.plist"];  

  16.    //输入写入  

  17.     [data writeToFile:filename atomically:YES];  

  18.       

  19.     //那怎么证明我的数据写入了呢?读出来看看  

  20.     NSMutableDictionary *data1 = [[NSMutableDictionary alloc] initWithContentsOfFile:filename];  

  21.     NSLog(@"%@", data1);  


使用Xcode自带的创建pilst文件功能,创建ErrorCode.plist

 如图:

  

 

 2.在项目中使用plist文件

  NSString *strErrorCodePath = [[NSBundle mainBundle]pathForResource:@"ErrorCode"    ofType:@"plist"];

 

  NSDictionary *dictErrorCode = [NSDictionary dictionaryWithContentsOfURL:[NSURLfileURLWithPath:strErrorCodePath]];

 

  NSDictionary *dictErrorPromp = [dictErrorCode objectForKey:@"ErrorPromp"];

 

 if (![self.msgCode isEqualToString:@""] && self.msgCode != nil) {

  NSString *strPromp = [dictErrorPromp objectForKey:self.msgCode];

    if (![strPromp isEqualToString:@""] && strPromp != nil) {

     [LoadingView showLoadingView:strPromp];

  }

  }

 

创建 PS_CONFIG.plist 文件,截图如下:

将PS_CONFIG.plist的使用方法创建一个单独的类处理

PSConfig.h文件

#import <Foundation/Foundation.h>

 

@interface PSConfig : NSObject {

 

}

+ (NSString*)getConfigFilePath;

+ (NSString*)getDocumentConfigFilePath;

+ (void)setDeviceTokenValue:(NSString *)value;

+ (NSString *)getDeviceTokenValue;

+ (void)setIsFirstInstallValue:(BOOL)value;

+ (BOOL)getIsFirstInstallValue;

+ (void)setIsLookedCheckOrderGuideValue:(BOOL)value;

+ (BOOL)getIsLookedCheckOrderGuideValue;

+ (void)setIsLookedCheckOrderGuide2Value:(BOOL)value;

+ (BOOL)getIsLookedCheckOrderGuide2Value;

+ (void)setIsLookedUserAddressGuideValue:(BOOL)value;

+ (BOOL)getIsLookedUserAddressGuideValue;

+ (void)setLastUpdateTimeValue:(NSString *)value;

+ (NSString *)getLastUpdateTimeValue;

@end

 

PSConfig.m文件

 

#import "PSConfig.h"

 

#define kConfigFileName @"PS_CONFIG"

#define kConfigFileType @"plist"

 

@implementation PSConfig

 

// 原始文件目录

+ (NSString*)getConfigFilePath{

 

NSString *configFilePath = [[NSBundlemainBundle]pathForResource:kConfigFileNameofType:kConfigFileType];

return configFilePath;

}

 

// 用来作更改的目录

+ (NSString*)getDocumentConfigFilePath{

 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMaskYES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *path = [documentsDirectorystringByAppendingPathComponent:@"PS_CONFIG.plist"];

NSFileManager *fileManager = [NSFileManagerdefaultManager];

BOOL isExist = [fileManager fileExistsAtPath:path];

if (!isExist) {

NSString *configFilePath = [self getConfigFilePath];

NSDictionary *configDic = [NSDictionarydictionaryWithContentsOfFile:configFilePath];

[configDic writeToFile:path atomically:YES];

}

return path;

}

 

+ (void)setDeviceTokenValue:(NSString *)value{

 

NSString *confi

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在iOS上使用Xcode进行离线打包,需要遵循以下步骤: 1. 确保你已经安装了Xcode并拥有一个有效的开发者账号。 2. 打开Xcode并选择 "File" -> "New" -> "Project"。 3. 选择 "iOS" -> "Application" -> "Single View App",并点击 "Next"。 4. 输入项目名称和其他信息,然后点击 "Next"。 5. 选择一个位置来保存你的项目文件,然后点击 "Create"。 6. 在左侧导航栏中选择你的项目,并在 "General" 选项卡下找到 "Identity" 部分。 7. 点击 "Team" 下拉菜单并选择你的开发者账号。 8. 关闭Xcode并在终端中打开你的项目文件夹。 9. 运行以下命令来创建一个离线打包的IPA文件: ``` xcodebuild clean archive -scheme <YourSchemeName> -archivePath <YourArchivePath.xcarchive> CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO ``` 其中,`<YourSchemeName>` 是你项目中的 scheme 名称,`<YourArchivePath.xcarchive>` 是你想要保存的归档文件的路径。 10. 运行以下命令来导出IPA文件: ``` xcodebuild -exportArchive -archivePath <YourArchivePath.xcarchive> -exportOptionsPlist <YourExportOptions.plist> -exportPath <YourIPAPath.ipa> ``` 其中,`<YourArchivePath.xcarchive>` 是你刚才创建的归档文件的路径,`<YourExportOptions.plist>` 是一个导出选项的配置文件,`<YourIPAPath.ipa>` 是你想要保存的IPA文件的路径。 11. 完成后,你应该可以在 `<YourIPAPath.ipa>` 路径下找到你的IPA文件。 请注意,此方法需要你已经有一个有效的开发者账号,并且你需要使用终端来执行命令。此外,此方法可能存在不稳定性和错误,因此请谨慎使用

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值