Skip to content

Instantly share code, notes, and snippets.

@croath
croath / how to get malloc info via dealloc instance memory address
Last active December 11, 2015 19:58
how to get malloc info via dealloc instance memory address // iOS develop
有时候app crash的时候会看到类似如下的信息,除此之外就再也没有其他信息了
MyApp [4413:40b] -[UIImage isKindOfClass]: message sent to deallocated instance 0x4dbb170
这时候的错误定位方法如下:
- 使用gdb调试时,在debug窗口输入:info malloc-history 0x4dbb170(这里写已经dead的内存地址
- 使用lldb调试[此方法仅适用于模拟器调试,需要勾选scheme中Malloc Stack选项],打开terminal,su权限(没su权限可能会报错)
输入:malloc_history 4413 0x4dbb170 //4413是这个app的进程pid,在报错信息中能找到MyApp [4413:40b]
输入以上语句之后会产生一系列log如下:(很多不用看直接跳到213行
---------------------------------------
malloc_history Report Version: 2.0
#pragma mark -
#pragma mark UIWebViewDelegate Methods
- (BOOL) webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if (_sessionChecked) {
[self log:@"session already checked."];
return YES;
@croath
croath / gist:4984421
Last active December 13, 2015 22:29
clear cookies in iOS
- (void)clearCookies{
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *each in cookieStorage.cookies) {
if ([[[each properties] objectForKey:NSHTTPCookieDomain] isEqualToString:@".douban.com"] &&
[[[each properties] objectForKey:NSHTTPCookieName] isEqualToString:@"bid"]) {
[cookieStorage deleteCookie:each];
NSDictionary* dic = [each properties];
[dic setValue:@"" forKey:NSHTTPCookieValue];
NSHTTPCookie* cookie = [NSHTTPCookie cookieWithProperties:dic];
[cookieStorage setCookie:cookie];
@croath
croath / note.md
Last active March 30, 2016 02:53
关于Objective-C warning的笔记。

关于Objective-C warning的笔记。

关于deprecated方法

在开发(重构)中会遇到需要更新、替换、方法的时候,这时候就需要deprecated标签来表明已经废弃的方法。

举例说明:

@croath
croath / setting_url_scheme.md
Last active December 14, 2015 04:39
iOS setting url scheme

Only available in iOS 5.x

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=Restrictions"]];

prefs:root=General&path=About
prefs:root=General&path=ACCESSIBILITY
prefs:root=AIRPLANE_MODE
prefs:root=General&path=AUTOLOCK
prefs:root=General&path=USAGE/CELLULAR_USAGE

prefs:root=Brightness

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
//awesome! need to check usr/include/AvailabilityInternal.h
@croath
croath / commands.sh
Created April 18, 2014 19:03
show command using rate
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)\
print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" \
| column -c3 -s " " -t | sort -nr | nl | head -n10
@croath
croath / rmapp.rb
Created April 23, 2014 06:52
Remove specific apps installed in iPhone simulator.
require 'fileutils'
class String
def numeric?
return true if self =~ /^\d+$/
true if Float(self) rescue false
end
end
def remove_app (app_name)
- (NSArray*)findAllLabelsOfView:(UIView*)view{
NSMutableArray *array = [NSMutableArray array];
NSArray *subViews = view.subviews;
if ([view isKindOfClass:[UILabel class]]) {
[array addObject:view];
}
if (subViews.count) {
[subViews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[array addObjectsFromArray:[self findAllLabelsOfView:obj]];
}];
var mc:CUnsignedInt = 0
var mlist:UnsafePointer<Method> = class_copyMethodList(UIImageView.classForCoder(), &mc);
println("\(mc) methods")
for var i:CUnsignedInt = 0; i < mc; i++ {
println("Method #\(i): \(sel_getName(method_getName(mlist.memory)))")
mlist = mlist.succ()
}