Skip to content

Instantly share code, notes, and snippets.

@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

@croath
croath / note.md
Last active March 30, 2016 02:53
关于Objective-C warning的笔记。

关于Objective-C warning的笔记。

关于deprecated方法

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

举例说明:

@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];
#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 / 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