iPhone编程的一些小技巧[增加中]
2011-12-19 21:26
281 查看
Home键相关事件
1. 休眠后委托事件
- (void)applicationWillResignActive:(UIApplication *)application
// applicationWillResignActive之后
- (void)applicationDidEnterBackground:(UIApplication *)application
2. 唤醒后的响应事件
- (void)applicationDidBecomeActive:(UIApplication *)application
关闭应用程序的方法
- (IBAction)closeApplication:(id)sender
{
UIApplication *application = [UIApplication sharedApplication];
if([application respondsToSelector:@selector(terminateWithSuccess)])
{
[application performSelector:@selector(terminateWithSuccess)];
}
}
实现全局量的一个方法
1.在AppDelegate中加入定义
@property (strong, nonatomic) xxx;
2.使用
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate xxx];
UITextField响应关闭软键盘方法
1.ViewController中加入UITextFieldDelegate
@interface ViewController : UIViewController <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textField;
2.textFieldShouldReturn函数
不要忘记:textField.delegate = self;
可放在- (void)viewDidLoad中
#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
NSLog(@"textFieldShouldReturn");//测试用
return YES;
}
iphone获取本机IP
-(NSString *)getAddress
{
char iphone_ip[255];
strcpy(iphone_ip,"127.0.0.1"); // if everything fails
NSHost* myhost =[NSHost currentHost];
if (myhost)
{
NSString *ad = [myhost address];
if (ad)
strcpy(iphone_ip,[ad cStringUsingEncoding:NSASCIIStringEncoding]);
}
return [NSString stringWithFormat:@"%s",iphone_ip];
}
URL获取图片
NSURL *imageURL = [NSURL URLWithString:@"http://www.baidu.com/img/baidu_logo.gif"];
NSData *photoData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [[UIImage alloc] initWithData:photoData];
m_ImageView.image = image;
iPhone获取本机号码
本机号码要是用户设置了可以获得:
[[NSUserDefaults standardUserDefaults] valueForKey:@"SBFormattedPhoneNumber"];
保护iPhone App版权的一个方法
iPhone应用的发布是通过iTunes,用户下载之后会对程序产生一个对应你iTunes帐号的签名。而破解,正是需要去掉这个签名,让它可以安装在 每一个帐号上。但是安装过程还是需要欺骗iTunes,告诉它这个程序是已经签名了的。
这个破解的签名在哪里呢?对了,就是每个应用或游戏下的Info.plist文件,如果你下载过破解的 iPhone应用来研究。就会发现所有的破解程序都有这个一个键值:
<key>SignerIdentity</key>
<string>Apple iPhone OS Application Signing</string>
那么保护破解最简单的入手点就是针对这个地方了。
打开xcode,在你需要检测破解的地方添加以下代码:
NSBundle *bundle = [NSBundle mainBundle];
NSDictionary *info = [bundle infoDictionary];
if ([info objectForKey: @"SignerIdentity"] != nil)
{
//你的代码
}
以上代码读取info.plist,如果发现了SignerIdentity的键,就执行你的代码。
$(BUILT_PRODUCTS_DIR)
记个目录
链接的一些用法
email可以使用[[UIApplication sharedApplication] openURL:[NSURL urlwithString:@"mailto//:a@c.com"]];或使用MFMailComposeViewController;
电话就是[[UIApplication sharedApplication] openURL:[NSURL urlwithString:@"tel//:10086"]];
跳转到appstore上面显示作者所有的程序的地址
http://phobos.apple.com/WebObjects/MZSearch.woa/wa/search?submit=seeAllLockups&media=software&entity=all&term=xxxxx
XXXXX换为自己公司名
评论链接
http://itunes.apple.com/us/app//id491232423?l=zh&ls=1&mt=8
NSInteger m_appleID = 491232423;
NSString *str = [NSString stringWithFormat:
@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",
m_appleID ];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
info.plist中一些属性的用法
info.plist 下找到 Application does not run in background 这个Boolean 设为 YES Home键退出应用
Status bar is initially hidden 这个Boolean 设为 YES 无状态条
[[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
程序比较重要的配置信息,可以放到info.plist文件中,然后在程序中可以方便的获取数据内容。既方便又快捷。
1. 在info.plist文件中添加一个ChannelID的内容。然后指定一个值。
2. 在程序中调用下边语句即可。
NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *channelID = [NSString stringWithFormat:@"%@", [infoDict objectForKey:@"ChannelID"]];
NSLog(@"ChannelID:%@", channelID);
1. 休眠后委托事件
- (void)applicationWillResignActive:(UIApplication *)application
// applicationWillResignActive之后
- (void)applicationDidEnterBackground:(UIApplication *)application
2. 唤醒后的响应事件
- (void)applicationDidBecomeActive:(UIApplication *)application
关闭应用程序的方法
- (IBAction)closeApplication:(id)sender
{
UIApplication *application = [UIApplication sharedApplication];
if([application respondsToSelector:@selector(terminateWithSuccess)])
{
[application performSelector:@selector(terminateWithSuccess)];
}
}
实现全局量的一个方法
1.在AppDelegate中加入定义
@property (strong, nonatomic) xxx;
2.使用
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate xxx];
UITextField响应关闭软键盘方法
1.ViewController中加入UITextFieldDelegate
@interface ViewController : UIViewController <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textField;
2.textFieldShouldReturn函数
不要忘记:textField.delegate = self;
可放在- (void)viewDidLoad中
#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
NSLog(@"textFieldShouldReturn");//测试用
return YES;
}
iphone获取本机IP
-(NSString *)getAddress
{
char iphone_ip[255];
strcpy(iphone_ip,"127.0.0.1"); // if everything fails
NSHost* myhost =[NSHost currentHost];
if (myhost)
{
NSString *ad = [myhost address];
if (ad)
strcpy(iphone_ip,[ad cStringUsingEncoding:NSASCIIStringEncoding]);
}
return [NSString stringWithFormat:@"%s",iphone_ip];
}
URL获取图片
NSURL *imageURL = [NSURL URLWithString:@"http://www.baidu.com/img/baidu_logo.gif"];
NSData *photoData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [[UIImage alloc] initWithData:photoData];
m_ImageView.image = image;
iPhone获取本机号码
本机号码要是用户设置了可以获得:
[[NSUserDefaults standardUserDefaults] valueForKey:@"SBFormattedPhoneNumber"];
保护iPhone App版权的一个方法
iPhone应用的发布是通过iTunes,用户下载之后会对程序产生一个对应你iTunes帐号的签名。而破解,正是需要去掉这个签名,让它可以安装在 每一个帐号上。但是安装过程还是需要欺骗iTunes,告诉它这个程序是已经签名了的。
这个破解的签名在哪里呢?对了,就是每个应用或游戏下的Info.plist文件,如果你下载过破解的 iPhone应用来研究。就会发现所有的破解程序都有这个一个键值:
<key>SignerIdentity</key>
<string>Apple iPhone OS Application Signing</string>
那么保护破解最简单的入手点就是针对这个地方了。
打开xcode,在你需要检测破解的地方添加以下代码:
NSBundle *bundle = [NSBundle mainBundle];
NSDictionary *info = [bundle infoDictionary];
if ([info objectForKey: @"SignerIdentity"] != nil)
{
//你的代码
}
以上代码读取info.plist,如果发现了SignerIdentity的键,就执行你的代码。
$(BUILT_PRODUCTS_DIR)
记个目录
链接的一些用法
email可以使用[[UIApplication sharedApplication] openURL:[NSURL urlwithString:@"mailto//:a@c.com"]];或使用MFMailComposeViewController;
电话就是[[UIApplication sharedApplication] openURL:[NSURL urlwithString:@"tel//:10086"]];
跳转到appstore上面显示作者所有的程序的地址
http://phobos.apple.com/WebObjects/MZSearch.woa/wa/search?submit=seeAllLockups&media=software&entity=all&term=xxxxx
XXXXX换为自己公司名
评论链接
http://itunes.apple.com/us/app//id491232423?l=zh&ls=1&mt=8
NSInteger m_appleID = 491232423;
NSString *str = [NSString stringWithFormat:
@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",
m_appleID ];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
info.plist中一些属性的用法
info.plist 下找到 Application does not run in background 这个Boolean 设为 YES Home键退出应用
Status bar is initially hidden 这个Boolean 设为 YES 无状态条
[[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
程序比较重要的配置信息,可以放到info.plist文件中,然后在程序中可以方便的获取数据内容。既方便又快捷。
1. 在info.plist文件中添加一个ChannelID的内容。然后指定一个值。
2. 在程序中调用下边语句即可。
NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *channelID = [NSString stringWithFormat:@"%@", [infoDict objectForKey:@"ChannelID"]];
NSLog(@"ChannelID:%@", channelID);
相关文章推荐
- Flex 编程的一些小技巧。不定期增加
- Flex 编程的一些小技巧。不定期增加
- 计算机小技巧集锦 (增加你计算机的安全系数以及一些问题的解决方法)
- iOS开发的一些小技巧22(后续增加)
- 关于java中一些小技巧
- 在原有项目上新增加扩展应用的一些吐槽
- 自己用到的一些jquery小技巧
- Matlab 中的一些小技巧(2)
- Javascript调试之console对象――你不知道的一些小技巧
- 仔细解说有关“DB2“数据库的一些小技巧-2
- Android studio中的一些小技巧
- ruby webdriver 启动chrome浏览器的一些小技巧
- 艾伟也谈项目管理,项目过程中所遇到的各种问题记录——有关MSChart的一些小技巧
- SQL查询的一些小技巧
- Python的一些小技巧小知识
- Ubuntu的一些使用小技巧【不断更新中】
- linux中的一些小技巧
- iOS开发的一些小技巧
- rails 中 使用 rabl 来生成 json 的时候 ,一些小技巧
- IPhone/IPad的一些使用小技巧