iOS项目开发经验:【常用代码3】

<3-1> 判断当前设备是否越狱  

+(BOOL)isJailbroken {
  BOOL isJailbroken = NO;
  NSString *cydiaPath = @”/Applications/Cydia.app”;
  NSString *aptPath = @”/private/var/lib/apt/”;
  if ([[NSFileManager defaultManager] fileExistsAtPath:cydiaPath] 
           || [[NSFileManager defaultManager] fileExistsAtPath:aptPath]){
     isJailbroken = YES;
  }
  return isJailbroken ;
}

<3-2> 隐藏状态

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];


<3-3>移动TableView滚动条位置
[tableView setContentOffset:CGPointMake(0, 0) animated:NO];


<3-4>代码方式给UIButton绑定事件

 UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 30)]; 
[button addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
button.cancelsTouchesInView = NO; //让手势不把事件消耗掉,可以继续向下传递


<3-5> 使用手势给图片绑定单击事件

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    imageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                                action:@selector(imageSingleTapAction:)];
    [imageView addGestureRecognizer:singleTapGesture];


<3-6>检查协议方法

    if(delegate && [delegate conformsToProtocol:@protocol(CopyDelegate)])
    {
    }

<3-7> 无缓存方式加载图片

[UIImage imageNamed]此方法加载图片会保存该图片的缓存,提供高速访问,程序结束才释放。
多图片使用时不宜使用,尤其是在Cell里面。

Cell里面可以使用下面的代码
NSString *imageName = @"image001.png";
NSRange range = [imageName rangeOfString:@"."];
NSString *file = [[NSBundle mainBundle] pathForResource:[imageName substringToIndex:range.location] ofType:[imageName pathExtension]];
NSData *imageData = [NSData dataWithContentsOfFile:file];	
[self.imageView setImage:[UIImage imageWithData:imageData]];


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS越狱开发中,常用的Hook检测包括以下几种: 1. 检测当前进程是否被其他进程注入 ``` void anti_injection() { char path[1024]; int ret = proc_pidpath(getpid(), path, sizeof(path)); if (ret <= 0) { NSLog(@"anti_injection: proc_pidpath failed"); exit(1); } if (strstr(path, "/Library/MobileSubstrate") != NULL) { NSLog(@"anti_injection: MobileSubstrate detected"); exit(1); } if (strstr(path, "/Library/Frameworks/CydiaSubstrate.framework") != NULL) { NSLog(@"anti_injection: CydiaSubstrate detected"); exit(1); } } ``` 2. 检测是否被调试 ``` void anti_debugging() { int name[4]; struct kinfo_proc info; size_t info_size = sizeof(info); name[0] = CTL_KERN; name[1] = KERN_PROC; name[2] = KERN_PROC_PID; name[3] = getpid(); if (sysctl(name, 4, &info, &info_size, NULL, 0) == -1) { NSLog(@"anti_debugging: sysctl failed"); exit(1); } if (info.kp_proc.p_flag & P_TRACED) { NSLog(@"anti_debugging: traced"); exit(1); } } ``` 3. 检测是否被hook ``` void anti_hooking() { const char *functionName = "ptrace"; void *handle = dlopen("/usr/lib/libc.dylib", RTLD_GLOBAL | RTLD_NOW); if (handle == NULL) { NSLog(@"anti_hooking: dlopen failed"); exit(1); } void *ptrace_func = dlsym(handle, functionName); if (ptrace_func == NULL) { NSLog(@"anti_hooking: dlsym failed"); exit(1); } if (ptrace_func != (void *)&ptrace) { NSLog(@"anti_hooking: hook detected"); exit(1); } } ``` 4. 检测是否被注入Cycript等调试工具 ``` void anti_cycript() { char *cycript = strstr(getenv("DYLD_INSERT_LIBRARIES"), "cycript"); if (cycript != NULL) { NSLog(@"anti_cycript: cycript detected"); exit(1); } } ``` 此外,还可以在代码中添加闪退检测断点,当程序发生闪退时就可以打断点进行调试,例如: ``` void crash_handler(int signal) { signal(SIGTRAP, NULL); NSLog(@"crash_handler: signal=%d", signal); exit(1); } void set_crash_handler() { signal(SIGTRAP, crash_handler); } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值