iPhone编程的一些小技巧[增加中]

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);



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值