奥对,忘了说了,Xcode7已经默认https连接了,自动锁定了http连接
Solution:
1. 在Info.plist中添加 NSAppTransportSecurity 类型 Dictionary.
2. 在 NSAppTransportSecurity 下添加 NSAllowsArbitraryLoads 类型Boolean,value为YES
接下来写显示商品详情的类
storyboard上面怎么连接我就不说了,直接上代码。
WebViewController.h
#import <UIKit/UIKit.h>
@interface WebViewController : UIViewController
@property (strong, nonatomic) NSString *stringURL;
@property (strong, nonatomic) NSString *shopName;
@property (weak, nonatomic) IBOutlet UIWebView *webView;
- (IBAction)back:(UIBarButtonItem *)sender;
@end
WebViewController.m
#import "WebViewController.h"
@interface WebViewController ()
@end
@implementation WebViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = [NSString stringWithFormat:@"%@", _shopName];
NSURL *url = [NSURL URLWithString:_stringURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)back:(UIBarButtonItem *)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
再来地图
MapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "MyAnnotation.h"
@interface MapViewController : UIViewController <MKMapViewDelegate>
@property (strong, nonatomic) NSString *longtitudeStr;
@property (strong, nonatomic) NSString *latitudeStr;
@property (strong, nonatomic) NSString *shopName;
@property (strong, nonatomic) NSString *shopAddress;
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (weak, nonatomic) IBOutlet MKMapView *map;
- (IBAction)back:(UIBarButtonItem *)sender;
@end
MapViewController.m
#import "MapViewController.h"
@interface MapViewController () {
CLLocationDegrees longitude;
CLLocationDegrees latitude;
}
@property (strong, nonatomic) CLLocation *targetLocation;
@property (strong, nonatomic) MyAnnotation *annotation;
- (void)gecodeToDisplayTargetLocation;
@end
@implementation MapViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = _shopAddress;
//定位请求
_locationManager = [CLLocationManager new];
[_locationManager requestWhenInUseAuthorization];
//经纬转换
longitude = (CLLocationDegrees)[_longtitudeStr floatValue];
latitude = (CLLocationDegrees)[_latitudeStr floatValue];
_targetLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
_map.delegate = self;
[self gecodeToDisplayTargetLocation];
}
- (void)gecodeToDisplayTargetLocation {
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:_targetLocation completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
//传过来1个数据,所以就一个
CLPlacemark *placemark = placemarks[0];
//显示地图缩放比例
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(placemark.location.coordinate, 500, 500);
[_map setRegion:viewRegion animated:YES];
//设置标注
_annotation = [MyAnnotation new];
_annotation.shopName = _shopName;
_annotation.address = _shopAddress;
_annotation.coordinate = placemark.location.coordinate;
[_map addAnnotation:_annotation];
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - MKMapDelegate implements
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
//使用可重用对象节省内存
MKPinAnnotationView *annotaionView = (MKPinAnnotationView *)[_map dequeueReusableAnnotationViewWithIdentifier:@"PIN_ANNOTATION"];
if (!annotaionView) {
annotaionView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PIN_ANNOTATION"];
}
//设置大头针颜色
annotaionView.pinColor = MKPinAnnotationColorPurple;
//大头针动态插入
annotaionView.animatesDrop = YES;
//显示附加信息在大头针处
annotaionView.canShowCallout = YES;
return annotaionView;
}
- (IBAction)back:(UIBarButtonItem *)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
至于SecondViewController我没有写代码,这里随便怎么处置了。