2013年1月28日星期一

iOS Making Call Using WebView with Country Code Number

      Currently My App has a problem making call with a number(say +861010010) with Country Code using WebView way.
Then I find that let the schema 'tel:' and 'tel://' has different effect when WebView load that url. I read Apple's Document and see that Apple is using the 'tel:' schema. So I changed 'tel://' to 'tel:', done~
      The following code is part of my Project, it can fix the wrong components in a mess string from ABRecordRef number value, i.e remain all the number and the prefix '+', so that the schema can be correctly.
      Hope this post can help people get the same prolem :)
      My Weibo is @洛石
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
- (void)callContact:(NSNotification *)notice
{
    if (!isMakingCall)
    {
        if ([[UIApplicationsharedApplication] canOpenURL:[NSURLURLWithString:@"tel:+861010010"]])
        {
            NSString *phoneNumber = [notice object];
            BOOL hasPlusString = [phoneNumber hasPrefix:@"+"];
            phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSetdecimalDigitCharacterSet] invertedSet]]
componentsJoinedByString:@""];//电话Url Schema里面有各种英文字符系统会不识别,所以要处理。
            if (hasPlusString)
            {
                phoneNumber = [NSStringstringWithFormat:@"+%@",phoneNumber];
            }
            NSString *tryPhoneNumber = [NSStringstringWithFormat:@"tel:%@",phoneNumber];
            if ([phoneNumber length]>0 && [[UIApplicationsharedApplication] canOpenURL:[NSURLURLWithString:tryPhoneNumber]])
            {
                isMakingCall = YES;              [selfperformSelectorOnMainThread:@selector(refreshMainTableView:) withObject:nilwaitUntilDone:YES];
                NSLog(@"callContact phoneNumber:%@",tryPhoneNumber);
                NSURL    *url = [NSURLURLWithString:tryPhoneNumber];
                if (dialWebview==nil)
                {
                    dialWebview = [[UIWebViewalloc] initWithFrame:CGRectMake(40, 373, 35, 40)];
                    // Make webview transparent
                    dialWebview.alpha = 0.0;
                    // Assume we are in a view controller and have access to self.view
                    // insert webview under call button so if user cancels the view
                    // doesn't interfere with normal button operation              [self.viewinsertSubview:dialWebviewbelowSubview:self.view];
                }
                [dialWebviewloadRequest:[NSURLRequestrequestWithURL:url]];
            }
            else
            {
                [OMGToastshowWithText:@"对不起,您拨打的不是电话号码。" duration:2];
            }
        }
        else
        {
            [OMGToastshowWithText:@"对不起,您的设备无法拨打电话。" duration:2];
        }
    }
}



------
My new business with my wife, wholesale meddle-to-high end men's seamless underwear in the Netherlands: https://ecosharelife.com

2013年1月5日星期六

iOS Memory Leaks with [[NSBundle mainBundle] loadNibNamed:owner:options:]

来自我的点点博客
http://senry.me/post/2012-12-21/40047740239

一直在用XIB中写很多UIView的内容以便重用和管理,但是最近写的有一系列XIB实现的View发现在Instruments有大量内存泄露。抽出的大概内容如下:
+ (SGXView *)getContactViewFromXibWithModel:(SGXModel *)model
{
   SGXView *view = nil;
   NSArray *nibArray = [[NSBundlemainBundleloadNibNamed:@"SGXView"owner:selfoptions:nil];//xib内的对象设置需要注意,不然会出错
   for (id obj in nibArray)
   {
       if ([obj isKindOfClass:[SGXView class]])
       {
           view = obj;
           break;
       }
   }
   if (view)
   {
       view.model = model;
       [view refreshView];
   }
   return view;
}

      refreshView中的代码是简单的几个Label复制之类的,但是这一系列写的时候比较懒,以类局部变量的形式写IBOutlet,而不是以前用@property(assign)写的IBOutlet连接变量和XIB内的对象。
      就是这么一个懒惰的行为导致了这一系列内存泄露,害我找了好久,又参照以前的写法,只对比出了以上连接变量的方法不同而已。虽然不是很明白为什么用@property就能防止不内存泄露,但是以后还是老老实实写标准代码吧~记录下,希望对未来有碰到相同泄露的网友有帮助。


------
My new business with my wife, wholesale meddle-to-high end men's seamless underwear in the Netherlands: https://ecosharelife.com

2012年11月23日星期五

How to install thoes under Xcode 4.5 (iOS 6)

       Recently when I need to get started with jailbreak dev, I find a guide here (Beginning Jailbroken iOS Development - Getting The Tools).
       But I get errors after step 6 to "make". Couse I'm in Xcode 4.5(iOS 6). I search for solution and finally get an Good Answer here(How to install thoes under Xcode 4.5 (iOS 6)). After all the steps, I can "make" and "make package" now! LOL~

2012年10月25日星期四

Print Method List of an iOS class


    Working with a SDK that has few public API Interface, I've to get methods inside it. So following code can help:
    int unsigned methodCount;
    Method *methods = class_copyMethodList([SDKCLASS class], &methodCount);
    for (int i = 0;i<methodCount;i++){
        NSLog(@"%@", NSStringFromSelector(method_getName(methods[i])));
    }
    And Done~

2012年8月9日星期四

Asynchronous NSURLConnection with NSOperation

     When I work on NSURLConnection with NSOperation today, I alloc a NSURLConnection like this

NSURLConnection* connection = [[NSURLConnection alloc] 
initWithRequest:urlRequest delegate:self];
And implements the delegate methods, but it seems that those
methods are not called at all. I search the problem in stackOverflow 
for some time and find a blog(here) that helps me know and solve the issue.
"If you are performing this on a background thread, the thread is 
probably exiting before the delegates can be called."
So I follow codes in that blog and modify code in my NSOperation object 
to keep the runloop form exiting is to just put it in an infinite loop:
- (void) start
{
  if (![self isCancelled])
  {
    connection_ = [[NSURLConnection alloc] initWithRequest: 
                          [NSURLRequest requestWithURL:download_.url  
                          cachePolicy:NSURLRequestReloadIgnoringLocalCacheData 
                          timeoutInterval:15] delegate:self]; 
    if (connection_ != nil)     
   { 
      [self willChangeValueForKey:@"isExecuting"]; 
      executing_ = YES; 
      [self didChangeValueForKey:@"isExecuting"]; 
    }    
    else 
    {       
      [self willChangeValueForKey:@"isExecuting"]; 
      finished_ = YES; 
      [self didChangeValueForKey:@"isExecuting"]; 
    } 
    while(!finished_) 
    { 
      [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode 
                               beforeDate:[NSDate distantFuture]]; 
    } 
  }
  else
  {
// If it's already been cancelled, mark the operation as finished.
    [self willChangeValueForKey:@"isFinished"]; 
    { 
      finished_ = YES; 
    } 
    [self didChangeValueForKey:@"isFinished"]; 
  }
}
This works well now :)



------
My new business with my wife, wholesale meddle-to-high end men's seamless underwear in the Netherlands: https://ecosharelife.com

2012年8月7日星期二

'libxml/xmlversion.h' file not found

     In Xcode 4.2 and 4.3 when facing this error, you can do following setting to fix it.
     In your build settings, for the key "Header Search Paths", add
"$(SDK_DIR)"/usr/include/libxml2




------
My new business with my wife, wholesale meddle-to-high end men's seamless underwear in the Netherlands: https://ecosharelife.com