To know date and time settings in device from an iPhone application

后端 未结 2 2045
借酒劲吻你
借酒劲吻你 2021-01-14 23:36

I want to know whether the user has set their device to automatically set the date and time in the Settings.app in iPhone. I need this information because I want to make use

2条回答
  •  生来不讨喜
    2021-01-15 00:09

    This is an alternate suggestion, I had similar problem for a conference app I was developing. I wanted to show some data to user only in the second day of conference.

    After discussing getting date option from device with our team. We decided not to use this approach because as you said some user may change date settings and also some user may be reluctantly set their device to other countries time and date zones where there may be date conflict issues for users.

    Finally we decided to create a simple web page and get http 200 and http 404 request for that info. You dont have to put your data or whatever to the server, we just wanted to get the response code from web.

    So lets say you have a webpage http://xxxxxxxxxxxxxx.pdf or .html we dont put any pdf files to server so user always get http 404 response in that case we disable or hide the related data/button/row whatever. In the second day of conference we put a dummy page so now user can get http 200 response, so we enable button/row/data.

    if you decide to use this approach download block for nsurlconnection from here

    then use following code:

    NSURL *theFileURL=[NSURL URLWithString:@"yoururl"];
     NSURLRequest *request = [NSURLRequest requestWithURL:theFileURL];
    
        [URLConnection asyncConnectionWithRequest:request
                                  completionBlock:^(NSData *data, NSURLResponse *response) {
                                      //get data and response
                                      if ([response isKindOfClass:[NSHTTPURLResponse class]])
                                      {
                                          NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse *) response;
                                          //NSString *fileMIMEType = [[httpResponse MIMEType] lowercaseString];
                                          NSLog(@"httpResponse.statusCode %i",httpResponse.statusCode);
                                          if (httpResponse.statusCode==200) {
                                              //correct respond show data
    
                                          }
                                          else if (httpResponse.statusCode==404)
                                          {
                                              //no file this
                                              NSLog(@"no file at the server");
    
                                          }
    
                                      }
                                      //[HUD removeFromSuperview];
    
    
                                  } errorBlock:^(NSError *error) {
                                      //get error
    
                                      NSLog(@"error %@",error);
                                  } uploadPorgressBlock:^(float progress) {
                                      //Upload progress (0..1)
                                  } downloadProgressBlock:^(float progress) {
                                      //Download progress (0.1)
                                      //progress += 0.01;
                                      //HUD.progress = progress;
                                  }];
    

提交回复
热议问题