2013年6月5日星期三

Using block with self api and avoids the retain cycle


      I'm leaving Beijing to Hangzhou, and join Alibaba wireless department now. Currently involved in a new product with a workmate.
      The project's iOS Deployment Target is iOS 5.0, so we begin to use ARC happily. Before this project, I always use MRC instead. And after learning changes between ARC and MRC we set off.
      But yesterday we found we seemed to have retain cycle in our project, and my first idea was this may have relation with using self api in block. Then I googled it, and found solution in StackOverflow here. Please check it out.



------

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

Using customized font in iOS, some thing to be noticed


1,add Font lib (.ttf or .odf) into Xcode Project,like FZKATJW.TTF (FangzhengKatong lib)。
2,add 'Fonts provided by application' in info.plist (and set item0's value as FZKATJW.TTF, add other font libs like this as well. Notice,suffix like .ttf or .otf should be added too).
3,Using the following code to print out the 'FontName' of the font we added in iOS runtime.
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
    NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
    fontNames = [[NSArray alloc] initWithArray:[UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]];
    for (indFont=0; indFont<[fontNames count]; ++indFont)
    {
        NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
    }
}
In my case the print info is like this:
2013-05-22 09:26:44.749 taobao4baby[502:c07] Family name: FZKaTong-M19S
2013-05-22 09:26:44.749 taobao4baby[502:c07] -Font name: FZKATJW--GB1-0
So we using the font with this code:
[UIFont fontWithName:@"FZKATJW--GB1-0" size:16]
Now you can using the new customized font freely~



------

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

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