Gowhich

Durban's Blog

创建一个user defaults方法有多个,最简单得快速创建方法:

1
NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];

添加数据到 user defaults:

1
[accountDefaults setObject:nameField.text forKey:UserDefaultNameKey];

也可以添加基本数据类型int, float, bool等,有相应得方法

1
[accountDefaults setBool:YES forKey:UserDefaultBoolKey];

实例代码:

1
2
3
NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
[accountDefaults setObject:@"yes" forKey:@"login"];
[accountDefaults setBool:YES forKey:@"login_state"];

从user defaults中获取数据:

1
2
[accountDefaults objectForKey:NCUserDefaultNameKey]
[accountDefaults boolForKey: UserDefaultBoolKey];

实例代码:

1
2
3
NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
NSLog(@"login = %@",[accountDefaults objectForKey:@"login"]);
NSLog(@"login_state = %d",[accountDefaults boolForKey: @"login_state"]);

要点: NSUserDefaults非常好用,并不需要用户在程序中设置NSUserDefaults的全局变量,需要在哪里使用NSUserDefaults的数据,那么就在哪里创建一个NSUserDefaults对象,然后进行读或者写操作。

针对同一个关键字对应的对象或者数据,可以对它进行重写,重写之后关键字就对应新的对象或者数据,旧的对象或者数据会被自动清理。

参考文章:http://blog.csdn.net/binyanye1/article/details/7633728

报错信息:

dyld: Library not loaded: @rpath/SenTestingKit.framework/Versions/A/SenTestingKit

文件我参考“http://www.carrotcoded.com/2012/10/10/sentestingkit-not-loaded-image-not-found/”

里面是这样的描述的

I am pretty sure that it was working perfectly in the old macbook pro, therefore i set out to google and see that alot of people actually hit this issue but there wasn’t any clear cut answer. To solve this basically, expand your solution -> Frameworks -> Remove the SenTestingKit from your project. This should resolve the issue. Note : Please remove reference not delete it.

大概的意思就是说,去掉这个SenTestingKit.framework框架就好了。

我去掉后确实可以了,也没有影响我的后面的运行

Note : Please remove reference not delete it.

注意这一句,别删掉了,这个可是框架自己本身就有的

毫秒级很简单

看代码示例

1
2
3
4
5
6
7
8
9
10
11
12
13
_imageNameDic = [NSMutableDictionary dictionaryWithCapacity:IMAGE_SUM];
for(int i=0;i<IMAGE_SUM;i++){
NSDate *date = [NSDate date];
NSTimeInterval aInterval =[date timeIntervalSince1970];

NSString *timeString = [NSString stringWithFormat:@"%f", aInterval];

NSString *uuid = [postData uuid];
NSString *filename = [NSString stringWithFormat:@"%@_%@.png",uuid,timeString];
NSMutableDictionary *tmpDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"",@"state",[NSString stringWithFormat:@"%@",filename],@"name", nil];
[_imageNameDic setObject:tmpDic
forKey:[NSString stringWithFormat:@"%d",i]];
}

自己最近在使用关于数据的存取和删除,于是自己就写了一个包括功能的类,自己用着还是蛮方便,再次分享一下

只贴代码:

StorageData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//
// StorageData.m
// xunYi7
//
// Created by david on 13-6-28.
// Copyright (c) 2013年 david. All rights reserved.
//

#import <CommonCrypto/CommonDigest.h>
#import "StorageData.h"
#import "xunYi7AppDelegate.h"

@implementation StorageData

-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
NSLog(@"开始结didReceiveData搜数据");
}

-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSLog(@"开始结didReceiveResponse搜数据");
}

-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"didFailWithError");
}

-(void) connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"connectionDidFinishLoading");
}

+(NSMutableData *)remoteFetchData:(NSString *)dataUrl{
NSString *currentDataFilePath = [[self dataPath] stringByAppendingPathComponent:[self fetchTodayDate]];

//创建目录
currentDataFilePath = [self createDirectory:currentDataFilePath];

currentDataFilePath = [currentDataFilePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",[self md5:dataUrl]]];

if([xunYi7AppDelegate isReachable]){
NSURL *url = [[NSURL alloc] initWithString:dataUrl];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60];

NSURLResponse *response = [[NSURLResponse alloc] init];
NSError *receiveDataError = [[NSError alloc] init];

NSMutableData *receivedData = (NSMutableData *)[NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&receiveDataError];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

return receivedData;
}else{
[xunYi7AppDelegate showNetworkMessage];
}

return nil;
}

+(NSMutableData *)localFetchData:(NSString *)dataUrl{

NSString *currentDataFilePath = [[self dataPath] stringByAppendingPathComponent:[self fetchTodayDate]];
NSString *yesterdayDataFilePath = [[self dataPath] stringByAppendingPathComponent:[self fetchYesterdayDate]];

//创建目录
currentDataFilePath = [self createDirectory:currentDataFilePath];

currentDataFilePath = [currentDataFilePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",[self md5:dataUrl]]];
yesterdayDataFilePath = [yesterdayDataFilePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",[self md5:dataUrl]]];

NSMutableData *localData = [self fromFilenamePathFetchLocalData:currentDataFilePath];

if(localData != nil){//本地数据
return localData;

}else{//远程获取数据

NSMutableData *receivedData = [self remoteFetchData:dataUrl];

if(receivedData != nil){
if([self storageDataToFile:receivedData fileName:currentDataFilePath]){
NSLog(@"保存成功");
[self removeDirectory];
}else{
NSLog(@"保存失败");
}
}else{
if((localData = [self fromFilenamePathFetchLocalData:yesterdayDataFilePath]) != nil){
return localData;
}
}
return receivedData;
}
return nil;
}

//md5加密字符串
+(NSString *)md5:(NSString *)str{
const char *cStr = [str UTF8String];
unsigned char result[16];
CC_MD5(cStr, strlen(cStr), result); // This is the md5 call
return [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}
//上传图片存储
+(void) saveUploadImage:(UIImage *)image withName:(NSString *)imageName{
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSError *error;

// 获取沙盒目录
NSString *fullPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
fullPath = [fullPath stringByAppendingPathComponent:@"tmpImage"];
if(![fileManager fileExistsAtPath:fullPath]){
[fileManager createDirectoryAtPath:fullPath
withIntermediateDirectories:YES
attributes:nil
error:&error];
}

fullPath = [fullPath stringByAppendingPathComponent:imageName];
NSData *imageData = UIImageJPEGRepresentation(image, 0.5);

// 将图片写入文件
[imageData writeToFile:fullPath atomically:NO];
}

//上传图片删除
+(void) removeUploadImage:(UIImage *)image withName:(NSString *)imageName{
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSError *error;

// 获取沙盒目录
NSString *fullPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
fullPath = [fullPath stringByAppendingPathComponent:@"tmpImage"];
if(![fileManager fileExistsAtPath:fullPath]){
[fileManager removeItemAtPath:fullPath error:&error];
}
}

//获取存储的图片
+(NSString *)fetchUploadImagePath:(NSString *)imageName{
NSString *fullPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
fullPath = [fullPath stringByAppendingPathComponent:@"tmpImage"];
fullPath = [fullPath stringByAppendingPathComponent:imageName];
return fullPath;
}

//判断文件是否存在
+(NSString *)isFileExists:(NSString *)fullpath{
NSFileManager *fileManager = [[NSFileManager alloc] init];
if([fileManager fileExistsAtPath:fullpath]){
return fullpath;
}
return nil;
}

//数据存储
//+(void)

//获取存储文件的目录
+(NSString *)dataPath{
//此处首先指定了图片存取路径(默认写到应用程序沙盒 中)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

//并给文件起个文件名
NSString *filePathDerectory = [paths objectAtIndex:0];

return filePathDerectory;
}

//获取指定文件的数据
+(NSMutableData *)fromFilenamePathFetchLocalData:(NSString *)filename{
//保存数据到指定文件中
NSFileManager *fileManager = [[NSFileManager alloc] init];
if([fileManager fileExistsAtPath:filename]){
NSData *data = [fileManager contentsAtPath:filename];
return [data mutableCopy];
}

return nil;
}

//存储数据到指定文件
+(BOOL) storageDataToFile:(NSData *)data fileName:(NSString *)fileName{
//保存数据到指定文件中
NSFileManager *fileManager = [[NSFileManager alloc] init];
if([fileManager createFileAtPath:fileName contents:data attributes:nil]){
return YES;
}else{
return NO;
}
}

//删除文件
+(void) deleteFile:(NSString *)fileName{
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSError *error;
[fileManager removeItemAtPath:fileName error:&error];
}

//获取今天的日期
+(NSString *) fetchTodayDate{
NSDate *currentDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
return [dateFormatter stringFromDate:currentDate];
}

//获取昨天的日期
+(NSString *) fetchYesterdayDate{
NSDate *yesterdayDate = [NSDate dateWithTimeIntervalSinceNow:-(24 * 60 * 60)];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
return [dateFormatter stringFromDate:yesterdayDate];
}

//获取前天的日期
+(NSString *) fetchYesterdayBeforeDate{
NSDate *yesterdayDate = [NSDate dateWithTimeIntervalSinceNow:-(2 * (24 * 60 * 60))];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
return [dateFormatter stringFromDate:yesterdayDate];
}

//获取存储文件的数据

//创建文件

//创建目录
+(NSString *) createDirectory:(NSString *)directoryName{
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSError *error;
if(![fileManager fileExistsAtPath:directoryName]){
[fileManager createDirectoryAtPath:directoryName
withIntermediateDirectories:YES
attributes:nil
error:&error];
if(error == nil){
return directoryName;
}else{
return directoryName;
}
}else{
return directoryName;
}
}
//删除文件
+(void) removeFile:(NSString *)filePath{
NSError *error;

NSFileManager *fileManager = [[NSFileManager alloc] init];
if([fileManager fileExistsAtPath:filePath]){
[fileManager removeItemAtPath:filePath error:&error];
}
if(error){
NSLog(@"error = %@",error);
}
}

//删除目录
+(void) removeDirectory{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *removeDirectoryPath = [documentsPath stringByAppendingPathComponent:[self fetchYesterdayBeforeDate]];
NSError *error;

NSFileManager *fileManager = [[NSFileManager alloc] init];
if([fileManager fileExistsAtPath:removeDirectoryPath]){
[fileManager removeItemAtPath:removeDirectoryPath error:&error];
}
if(error){
NSLog(@"error = %@",error);
}
}
@end
StorageData.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
// StorageData.h
// xunYi7
//
// Created by david on 13-6-28.
// Copyright (c) 2013年 david. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface StorageData : NSObject<NSURLConnectionDataDelegate, NSURLConnectionDelegate>

+(NSMutableData *)remoteFetchData:(NSString *)dataUrl;
+(NSMutableData *)localFetchData:(NSString *)dataUrl;
+(void) saveUploadImage:(UIImage *)image withName:(NSString *)imageName;
+(NSString *) uploadImage:(UIImage *)image withName:(NSString *)imageName;
+(NSString *) fetchUploadImagePath;
+(NSString *) fetchUploadImagePath:(NSString *)imageName;
+(void) removeUploadImage:(UIImage *)image withName:(NSString *)imageName;
+(NSString *)isFileExists:(NSString *)fullpath;
+(void) removeFile:(NSString *)filePath;
@end

有不完善的地方,希望指正和修改

关于UISegmentControl设置背景色的问题,我也遇到了,还查找了不少的资料,最终答案我在文档里面找到了。

链接我记录一下:https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UISegmentedControl_Class/Reference/UISegmentedControl.html

搜索一下tintcolor就可以知道了,说的很清楚的

tintColor The tint color of the segmented control. @property(nonatomic, retain) UIColor *tintColor Discussion The default value of this property is nil (no color). UISegmentedControl uses this property only if the style of the segmented control is UISegmentedControlStyleBar.

说的就是,首先有个属性要改一下

1
sexSegment.segmentedControlStyle = UISegmentedControlStyleBar;

下面代码是我的:

1
2
3
4
5
6
7
8
9
10
11
12
NSArray *item = [[NSArray alloc] initWithObjects:@"男",@"女", nil];

UISegmentedControl *sexSegment = [[UISegmentedControl alloc] initWithItems:item];
sexSegment.layer.borderWidth = 0.0;
sexSegment.tintColor = [ColorConfig NavigationColor];
sexSegment.segmentedControlStyle = UISegmentedControlStyleBar;
[sexSegment setFrame:CGRectMake(segmentX, segmentY, segmentWidth, segmentHeight)];
[sexSegment addTarget:self
action:@selector(selectSex:)
forControlEvents:UIControlEventValueChanged];

[_contentView addSubview:sexSegment];

最近刚刚接触到这个东西,感觉好神奇一样,就试着用了一下,哈哈,果然还不错:

代码如下,很简单的例子,不寒有任何的杂质

1
2
3
4
5
6
7
8
9
10
11
NSArray *item = [[NSArray alloc] initWithObjects:@"男",@"女", nil];

UISegmentedControl *sexSegment = [[UISegmentedControl alloc] initWithItems:item];
sexSegment.segmentedControlStyle = UISegmentedControlStyleBar;
[sexSegment setSegmentedControlStyle:UISegmentedControlStylePlain];
[sexSegment setFrame:CGRectMake(segmentX, segmentY, segmentWidth, segmentHeight)];
[sexSegment addTarget:self
action:@selector(selectSex:)
forControlEvents:UIControlEventValueChanged];

[_contentView addSubview:sexSegment];

如果要实现这个过程的话,需要几个步骤

第一步就是controller的操作

在要操作的控制器中添加如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
function actions()
{
return [
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha' => [
'class' => 'CCaptchaAction',
'backColor' => 0xFFFFFF,
'maxLength' => '8', // 最多生成几个字符
'minLength' => '7', // 最少生成几个字符
'height' => '40',
'width' => '230',
],
];

}

function accessRules()
{
return [
['allow',
'actions' => ['captcha'],
'users' => ['*'],
],
];
}

第二步就是view的操作

在要显示验证码的地方添加如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
<div class="control-group">
<?php $this->widget('CCaptcha',array(
'showRefreshButton'=>true,
'clickableImage'=>false,
'buttonLabel'=>'刷新验证码',
'imageOptions'=>array(
'alt'=>'点击换图',
'title'=>'点击换图',
'style'=>'cursor:pointer',
'padding'=>'10')
)); ?>
</div>

第三步就是LoginForm的操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

/**
* LoginForm class.
* LoginForm is the data structure for keeping
* user login form data. It is used by the 'login' action of 'SiteController'.
*/
class LoginForm extends CFormModel
{
public $username;
public $password;
public $rememberMe;
public $verifyCode;
private $_identity;

/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
public function rules()
{
return [
// username and password are required
// array('username, password', 'required'),
['username', 'required', 'message' => '登录帐号不能为空'],
['password', 'required', 'message' => '密码不能为空'],
['verifyCode', 'required', 'message' => '验证码不能为空'],
['verifyCode', 'captcha', 'on' => 'login', 'allowEmpty' => !Yii::app()->admin->isGuest],
// rememberMe needs to be a boolean
['rememberMe', 'boolean'],
// password needs to be authenticated
['password', 'authenticate'],
];
}

/**
* Declares attribute labels.
*/
public function attributeLabels()
{
return [
'rememberMe' => '下次记住我',
'verifyCode' => '验证码',
];
}

/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute, $params)
{
if (!$this->hasErrors()) {
$this->_identity = new UserIdentity($this->username, $this->password);
if (!$this->_identity->authenticate()) {
$this->addError('password', '帐号或密码错误.');
}
}
}

public function validateVerifyCode($verifyCode)
{
if (strtolower($this->verifyCode) === strtolower($verifyCode)) {
return true;
} else {
$this->addError('verifyCode', '验证码错误.');
}
}

/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
public function login()
{
if (null === $this->_identity) {
$this->_identity = new UserIdentity($this->username, $this->password);
$this->_identity->authenticate();
}
if (UserIdentity::ERROR_NONE === $this->_identity->errorCode) {
$duration = $this->rememberMe ? 3600 * 24 * 30 : 0; // 30 days
Yii::app()->user->login($this->_identity, $duration);
return true;
} else {
return false;
}
}
}

第四步,实现验证的过程,那么具体的查看我自己的写的一个方式,在第三部已经写好了

validateVerifyCode就是啦,可以在controller里面调用

我的调用如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
function actionLogin()
{
$model = new LoginForm;
if (isset($_POST['ajax']) && 'login-form' === $_POST['ajax']) {
echo CActiveForm::validate($model);
Yii::app()->end();
}

if (isset($_POST['LoginForm'])) {
$model->attributes = $_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if ($model->validate() &&
$model->validateVerifyCode($this->createAction('captcha')->getVerifyCode()) &&
$model->login()) {
$this->redirect(CController::createUrl('default/index'));
}
}
$this->render('login', ['model' => $model]);
}

刚接触ios开发的童鞋应该会对于app版本号吗有些疑问,因为target不仅仅在summary中有版本号,同样在Info.plist等地方也有版本号码的地方,一头乱码,不知吗?其实xcode在summary中已经将app最基本的设置进行了全面的封装,其余的plist,build setting等地方会跟着summary设置的改变而改变。

一个version,一个build,都是设置版本的地方,有什么区别呢?

在ios中(Android等工程中也一样),有两种version,一种是 CFBundleVersion (“Bundle Version”),也就是我们看到的version,另一种是CFBundleShortVersionString (“Bundle version string, short”),也就是我们看到的Build。

普通情况下,我们只使用version即可,设置为”1.0”, “1.1”, “2.0” , etc,但如果你要使用两个版本号时候,需要将build设置为1,2,3…等递增的整数,有什么用呢?

version我们可以通过AppStore、itunes或其它软件看到,是给用户看的,而build是我们在团队开发中内部只用的,只有我们自己可以看到。比如团队打算发布1.0版本的时候,会发布很多build版本供测试或QA团队进行测试,你发布了很多build,因为一直在修改着代码,因此当你收到一条bug信息时候,你怎么知道是那个build引起的问题呢,这时候build版本号的有点就可以体现出来了,不是吗。

我这里有一段代码,可以在xcode编译时候自动增加build号码。

先把 Info.plist 里的版本号改成某个数字,然后 Targets → your target → Build Phases → Run Script 的地方加上:

1
2
3
4
version=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $PRODUCT_SETTINGS_PATH`
version=`expr $version + 1`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $version" $PRODUCT_SETTINGS_PATH
#/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $version" $PRODUCT_SETTINGS_PATH 这行代码会让version也自增,一般不需要

参考:http://blog.csdn.net/shencaifeixia1/article/details/8221273#

在Xcode中当你在更新了你得证书而再重新编译你的程序,真机调试一直会出现 Code Sign error: Provisioning profile ‘XXXX’ can’t be found是不是会另你很恼火。下面说说解决方法,让你很好的解决这个问题。

1.关闭你的项目,找到项目文件XXXX.xcodeproj,在文件上点击右键,选择“显示包内容”(Show Package Contents)。会新打开一个Finder。注:其实XXXX.xcodeproj就是一个文件夹,这里新打开的一个Finder里面的三个文件就是该XXXX.xcodeproj文件夹里面的文件。

2.在新打开的Finder中找到project.pbxproj,并且打开。在这之中找到你之前的证书的编码信息。我之前报的错误信息是

Code Sign error: Provisioning profile ‘37D44E7F-0339-4277-9A82-C146A944CD46’,所以我用查找的方式找到了所有包括37D44E7F-0339-4277-9A82-C146A944CD46的行,并且删除。

3.保存,重新启动你的项目,再编译。就OK了。

参考:http://www.douban.com/note/131009422/

如果是 // 就会默认去调用protected/views/layouts,//代表 绝对路径
其实 就是 绝对和相对的关系/代表相对路径,如module/user下的layout
用单斜杠的话默认会先找当前已经激活的模块底下的view,若当前未有激活的模块则从系统根目录下开始找,双斜杠的话就直接从系统根下开始找

Yii framework已经定义的命名空间常量

system: 指向Yii框架目录; YII\framework
zii: 指向zii library 目录; YII\framework\zii
*application : 指向应用程序基本目录; protected*
*webroot: 指向包含里入口脚本 文件的目录. 此别名自 1.0.3 版起生效. *
ext : 指向包含所有第三方扩展的目录, 从版本 1.0.8 可用; \protected\extensions

1
2
3
4
5
6
Yii::getPathOfAlias('zii'); 
Yii::import ('zii.*');
Yii::setPathOfAlias('backend', $backend);
'import' => [
'backend.models.*',
]

应用的主目录是指包含所有安全系数比较高的PHP代码和数据的根目录。在默认情况下,这个目录一般是入口代码所在目录的一个目录: protected 。这个路径可以通过在application configuration里设置 basePath来改变.
YII framework路径

1
Yii::getFrameworkPath()

protected/runtime

1
Yii::app()->getRuntimePath();

protected/venders目录

1
Yii::import('application.venders.*');

或在protected/config/main.php说明

1
2
3
4
'import '=> [   
// ......
'application.venders.*',
],

插入meta信息

1
2
3
4
5
6
Yii::app()->clientScript->registerMetaTag('关键字','keywords');  
Yii::app()->clientScript->registerMetaTag('一些描述','description');
Yii::app()->clientScript->registerMetaTag('作者','author');
Yii::app()->clientScript->registerMetaTag(' text/html;charset=utf-8', null, 'Content-Type');
//<link rel="alternate" type="application/rss+xml" href="http://www.dreamdu.com/feed/" />
Yii::app()->clientScript->registerLinkTag('alternate','application/rss+xml',$this->createUrl('/feed'));

如何在控制器添加CSS文件或JavaScript文件

1
2
3
4
5
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/my.css');  
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/css/my.js');
<?php echo $this->module->assetsUrl; ?>/css/main.css
//调用YII框架中framework/web/js/source的js,其中registerCoreScript key调用的文件在framework/web/js/packages.php列表中可以查看
Yii::app()->clientScript->registerCoreScript('jquery');

在view中得到当前controller的ID方法:

1
Yii::app()->getController()->id;  

在view中得到当前action的ID方法:

1
Yii::app()->getController()->getAction()->id;  

yii获取ip地址

1
Yii::app()->request->userHostAddress; 

yii判断提交方式

1
Yii::app()->request->isPostRequest 

得到当前域名:

1
Yii::app()->request->hostInfo

得到proteced目录的物理路径

1
YII::app()->basePath; 

获得上一页的url以返回

1
Yii::app()->request->urlReferrer; 

得到当前url

1
Yii::app()->request->url; 

得到当前home url

1
Yii::app()->homeUrl 

得到当前return url

1
Yii::app()->user->returnUrl 

项目路径

1
2
3
4
dirname(Yii::app()->BasePath)  
Yii::app()->getBaseUrl(true);
<?php echo $this->getLayoutFile('main'); ?>
$this->redirect('index.php?r=admin/manage');

createUrl()

1
2
3
4
5
echo $this->createUrl('urlBoyLeeTest');  
//out => /yii_lab/index.php?r=lab/urlBoyLeeTest
$this->createUrl('post/read') // /index.php/post/read
<?php echo Yii::app()->request->baseUrl; ?>/css/screen.css
Yii::app()->theme->baseUrl.'/images/FileName.gif'

createAbsoluteUrl()

1
2
echo $this->createAbsoluteUrl('urlBoyLeeTest');  
//out => http://localhost/yii_lab/index.php?r=lab/urlBoyLeeTest
0%