ios

How to find the current season through any iOS API?


Is there anyway in iOS to find the current season (Spring, Summer, Winter, Fall) of the current location?

Seasons are different in different part of the world. I might experience different season in Australia when during the same time season in USA is something else.

Any weather API or something that returns the season of that place?


Solution

  • First get the coordinates of the user's current location:

    CLLocationManager *lm = [[CLLocationManager alloc] init];
    lm.delegate = self;
    lm.desiredAccuracy = kCLLocationAccuracyBest;
    lm.distanceFilter = kCLDistanceFilterNone; 
    [lm startUpdatingLocation];
    CLLocation *location = [lm location];
    CLLocationCoordinate2D coord;
    coord = [location coordinate];
    

    Then get the current date:

    NSDate* currentDate = [NSDate date];
    

    That's all you need, I think. Determine if the user is above or below the equator, and store the dates of season changes as constants.