iOS get SSID

- (id)fetchSSIDInfo {
    NSArray *ifs = (__bridge_transfer NSArray *)CNCopySupportedInterfaces();
    NSLog(@"Supported interfaces: %@", ifs);
    NSDictionary *info;
    for (NSString *ifnam in ifs) {
        info = (__bridge_transfer NSDictionary *)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
        NSLog(@"%@ => %@", ifnam, info);
        if (info && [info count]) { break; }
    return info;




DNS多点部署IP Anycast+BGP实战分析



参考 Sina的实现(可适当简化)

// 如果HttpDNS不可用,使用系统域名解析服务(libresolv.dylib)

使用NSURLProtocol自定义URL Loading过程 (实现domain -> ip全局转化)


Overriding TLS Chain Validation Correctly

AFNetWorking SSL Pinning Mode

NSCalendar get weeks on month (bug on iOS7)

使用NSCalendar类 计算某月中一共有多少个星期时,以下方法并不可靠

NSRange range = [calendar rangeOfUnit: NSWeekCalendarUnit
                                   inUnit: NSMonthCalendarUnit

- (NSUInteger)numberOfWeeksInMonthForDate:(NSDate *)date{
    NSDate *lastDayOfMonth = [self lastDayOfMonthForDate:date];
     计算一个月里有多少个星期 不能用rangeOfUnit 方法计算,这是iOS的bug
    NSRange range = [_calendar rangeOfUnit:NSCalendarUnitWeekOfMonth inUnit:NSCalendarUnitMonth forDate:date];
    NSUInteger numberOfDaysThisMonthError = [_calendar rangeOfUnit:NSCalendarUnitWeekOfMonth inUnit:NSCalendarUnitMonth forDate:date].length;
    NSLog(@"%@===>本月一共(%lu)周(ERROR)",date,(unsigned long)numberOfDaysThisMonthError);
    // range == {NSNotFound,NSNotFound}
    NSUInteger numberOfDaysThisMonth = [self.calendar components:NSCalendarUnitWeekOfMonth fromDate:lastDayOfMonth].weekOfMonth;
    NSLog(@"%@===>本月一共(%lu)周",date,(unsigned long)numberOfDaysThisMonth);
    return numberOfDaysThisMonth;



- (NSRange)rangeOfUnit:(NSCalendarUnit)smaller
               forDate:(NSDate * _Nonnull)date



The smaller calendar unit.


The larger calendar unit.


The absolute time for which the calculation is performed.

Return Value

The range of absolute time values smaller can take on in larger at the time specified by date. Returns{NSNotFound, NSNotFound} if larger is not logically bigger than smaller in the calendar, or the given combination of units does not make sense (or is a computation which is undefined).


You can use this method to calculate, for example, the range the Day unit can take on in the Month in whichdate lies.


Available in iOS 2.0 and later.


Week-Based Calendars

A week-based calendar is defined by the weeks of a year. Instead of the year, month, and day of a date, a week-based calendar is defined by the week-year, the week number, and a weekday.

However, this can be complicated when the first week of the calendar overlaps the last week of the previous year’s calendar. In this case there are two important properties of the calendar:

  1. What is the first day of the week?
  2. How many days does a week near the beginning of the year have to have within the ordinary calendar year for it to be considered the first week in the week-based calendar year?

A week-based calendar’s first day of the year is on the first day of the week. The first week is preferred to be the week containing Jan 1 if that week satisfies the defined answer for the second point above.

For example, suppose the first day of the week is defined as Monday, in a week-based calendar interpretation of the Gregorian calendar. Consider the 2009/2010 transition shown in Table 1 and Table 2:

Table 1  December 2009 Calendar
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
20 21 22 23 24 25 26
27 28 29 30 31

Table 2  January 2010 Calendar
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16

Since the first day of the week is Monday, the 2010 week-based calendar year can begin either December 28 or January 4. That is, December 30, 2009 (ordinary) could be December 30, 2010 (week-based).

To choose between these two possibilities, there is the second criterion. Week Dec 28 – Jan 3 has 3 days in 2010. Week Jan 4-Jan 10 has 7 days in 2010.

If the minimum number of days in a first week is defined as 1 or 2 or 3, the week of Dec 28 satisfies the first week criteria and would be week 1 of the week-based calendar year 2010. Otherwise, the week of Jan 4 is the first week.

As another example, suppose you wanted to define a week-based calendar such that the first week of the calendar year begins with the first occurrence of a specific weekday.

In Table 2 Monday January 4 is the first Monday of the ordinary year, so the week-based calendar begins on that day. What you are requesting then is that the first week of your week-based calendar is entirely within the new ordinary year or that the minimum number of days in first week is 7.

The NSYearForWeekOfYearCalendarUnit is the year number of a week-based calendar interpretation of the calendar you’re working with, where the two properties of the week-based calendar discussed in above correspond to these two NSCalendar properties: firstWeekday and minimumDaysInFirstWeek.