[英]My app crashes immediately after startup
正如标题所写,我的应用程序启动后立即崩溃。 我真的不知道该怎么办。 谢谢你的帮助。 这是代码:
#import "ViewController.h"
@import CoreLocation;
@interface ViewController () <CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (weak, nonatomic) IBOutlet UILabel *location;
@property (weak, nonatomic) IBOutlet UILabel *date;
@end
@implementation ViewController
-(void)viewDidLoad
{
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
//date
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMMM d, YYYY"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@", dateString);
self.date.text = (@"%@", dateString);
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"%@", [locations lastObject]);
self.location.text = (@"%@", [locations lastObject]);
}
@end
崩溃后显示以下内容: http : //i.stack.imgur.com/k0eVO.png
您的代码不完整,能否签出并再次发布
你必须
@selector(requestWhenInUseAuthorization)
并且您尚未设置函数requestWhenInUseAuthorization
您在哪种方法内放置以下代码。 您已将其放置在viewDidLoad下,但它不在任何方法内。 正确检查您的代码
[self.locationManager startUpdatingLocation];
//date
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMMM d, YYYY"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@", dateString);
self.date.text = (@"%@", dateString);
}
在您的应用中应用异常断点,然后重试。它将告诉您崩溃的确切位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.