iOS get SSID

http://stackoverflow.com/questions/5198716/iphone-get-ssid-without-private-library/5198968#5198968

- (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;
}

HttpDNS说开去

 

【鹅厂网事】全局精确流量调度新思路-HttpDNS服务详解

http://mp.weixin.qq.com/s?__biz=MzA3ODgyNzcwMw==&mid=201837080&idx=1&sn=b2a152b84df1c7dbd294ea66037cf262&scene=2&from=timeline&isappinstalled=0&utm_source=tuicool

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

http://www.linuxidc.com/Linux/2014-08/105816.htm

如何对抗APP“域名劫持”和“解析失败”问题?

http://www.oschina.net/question/1401206_229818

创建一个HttpDNSLib(专门负责DNS查询)

参考 Sina的实现(可适当简化)
https://github.com/SinaMSRE/HTTPDNSLib

// 如果HttpDNS不可用,使用系统域名解析服务(libresolv.dylib)
http://www.opensource.apple.com/source/libresolv/libresolv-57/

使用NSURLProtocol自定义URL Loading过程 (实现domain -> ip全局转化)
https://github.com/rnapier/RNCachingURLProtocol

使用HttpDNS后,使用https协议,如果直接用ip地址访问服务器会出现证书验证出错(证书上是用Domain,建立连接时用的是ip,SSL在验证证书时出错),这样就需要改变系统默认的证书链验证逻辑

Overriding TLS Chain Validation Correctly

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/OverridingSSLChainValidationCorrectly.html#//apple_ref/doc/uid/TP40012544

AFNetWorking SSL Pinning Mode

http://security.stackexchange.com/questions/29988/what-is-certificate-pinning
https://possiblemobile.com/2013/03/ssl-pinning-for-increased-app-security/

NSCalendar get weeks on month (bug on iOS7)

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

NSRange range = [calendar rangeOfUnit: NSWeekCalendarUnit
                                   inUnit: NSMonthCalendarUnit
                                  forDate:date];

http://stackoverflow.com/questions/2443044/nscalendar-problem-getting-weeks-in-a-month


- (NSUInteger)numberOfWeeksInMonthForDate:(NSDate *)date{
    
    NSDate *lastDayOfMonth = [self lastDayOfMonthForDate:date];
    
    /*
     
     计算一个月里有多少个星期 不能用rangeOfUnit 方法计算,这是iOS的bug
     
     http://stackoverflow.com/questions/2443044/nscalendar-problem-getting-weeks-in-a-month
     
     https://devforums.apple.com/thread/41850
     
     */
    
    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;
}

Declaration

OBJECTIVE-C

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

Parameters

smaller

The smaller calendar unit.

larger

The larger calendar unit.

date

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).

Discussion

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

Availability

Available in iOS 2.0 and later.

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/DatesAndTimes/Articles/dtCalendricalCalculations.html

 

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.