Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用重要位置管理器的应用程序在设备上意外关闭,但在模拟器上未关闭_Objective C_Ios6_Location - Fatal编程技术网

Objective c 使用重要位置管理器的应用程序在设备上意外关闭,但在模拟器上未关闭

Objective c 使用重要位置管理器的应用程序在设备上意外关闭,但在模拟器上未关闭,objective-c,ios6,location,Objective C,Ios6,Location,我希望有人能帮助我。我正在xcode 4.5.2上开发一个iOS 6应用程序,该应用程序使用重大更改位置服务,它检测到本地化使用反向地理编码,并使用web服务将国家代码、adminArea、subAdminArea、locality和sublocality上传到在线数据库。在iphone模拟器上,它工作正常,但在iOS设备上,它会毫无理由地直接关闭。如果我将位置服务停用到我的应用程序,它会正常运行,但当它有权使用这些服务时,它会在一秒钟内关闭 代码如下: #import "sea

我希望有人能帮助我。我正在xcode 4.5.2上开发一个iOS 6应用程序,该应用程序使用重大更改位置服务,它检测到本地化使用反向地理编码,并使用web服务将国家代码、adminArea、subAdminArea、locality和sublocality上传到在线数据库。在iphone模拟器上,它工作正常,但在iOS设备上,它会毫无理由地直接关闭。如果我将位置服务停用到我的应用程序,它会正常运行,但当它有权使用这些服务时,它会在一秒钟内关闭

代码如下:

        #import "searchViewController.h"
    #import <CoreLocation/CoreLocation.h>
    #import "resultViewController.h"

    @interface searchViewController () <UIPickerViewDataSource, UIPickerViewDelegate, CLLocationManagerDelegate, NSXMLParserDelegate>
    @property (weak, nonatomic) IBOutlet UITextView *errorSearchTextView;
    - (IBAction)searchButton:(id)sender;
    @property (weak, nonatomic) IBOutlet UIPickerView *bloodTypePicker;

    @end

    @implementation searchViewController

    @synthesize bloodType,locationManager,geocoder, webData, xmlParser, soapResults, localizacion, usuarios, correos, coincidencias;

- (void)viewDidLoad
{
    [super viewDidLoad];
    bloodType = [[NSArray alloc] initWithObjects:@"A+", @"A-", @"B+", @"B-", @"O+", @"O-", @"AB+", @"AB-", nil];
    [self startLocating];//here is where i start the location monitoring
    // Do any additional setup after loading the view.
}
//这些是在接收到位置更新时调用的方法

-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *location = [locations lastObject];
    [self geocoder:location];
    localizacion = 0;
}

//metodo para el geocoder
-(void) geocoder:(CLLocation *)location
{
    if (!geocoder) geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:location  completionHandler:^(NSArray *placemarks, NSError *error) {
        if ([placemarks count]>0)
        {
            NSString *usuario = [[NSUserDefaults standardUserDefaults] stringForKey:@"usuario"];
            CLPlacemark *place = [placemarks objectAtIndex:0];
            NSURL *url = [NSURL URLWithString:@"here goes the web service url"];
            NSMutableString *soapMessage = [[NSMutableString alloc] init];
            [soapMessage appendString:@"<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:localizacionWSDL\">"
             "<soapenv:Header/>"
             "<soapenv:Body>"
                "<urn:actualiza soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
             "<username xsi:type=\"xsd:string\">"];
            [soapMessage appendString:usuario];
            [soapMessage appendString:@"</username>"
             "<latitude xsi:type=\"xsd:string\">"];
            [soapMessage appendString:[NSString stringWithFormat:@"%f",location.coordinate.latitude] ];
            [soapMessage appendString:@"</latitude>"
             "<longitude xsi:type=\"xsd:string\">"];
            [soapMessage appendString:[NSString stringWithFormat:@"%f",location.coordinate.longitude]];
            [soapMessage appendString:@"</longitude>"
             "<countryCode xsi:type=\"xsd:string\">"];
            [soapMessage appendString:place.ISOcountryCode];
            [soapMessage appendString:@"</countryCode>"
             "<adminArea xsi:type=\"xsd:string\">"];
            [soapMessage appendString:place.administrativeArea];
            [soapMessage appendString:@"</adminArea>"
             "<subAdminArea xsi:type=\"xsd:string\">"];
            [soapMessage appendString:place.subAdministrativeArea];
            [soapMessage appendString:@"</subAdminArea>"
             "<locality xsi:type=\"xsd:string\">"];
            [soapMessage appendString:place.locality];
            [soapMessage appendString:@"</locality>"
             "<subLocality xsi:type=\"xsd:string\">"];
            [soapMessage appendString:place.subLocality];
            [soapMessage appendString:@"</subLocality>"
             "</urn:actualiza>"
             "</soapenv:Body>"
             "</soapenv:Envelope>"];
            NSMutableURLRequest *theResquest = [NSMutableURLRequest requestWithURL:url];
            NSString *messageLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
            [theResquest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
            [theResquest addValue:@"urn:LoginAction" forHTTPHeaderField:@"SOAPAction"];
            [theResquest addValue:messageLength forHTTPHeaderField:@"Content-Length"];
            [theResquest setHTTPMethod:@"POST"];
            [theResquest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
            webData = [NSMutableData data];
            localizacion = 0;
            NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theResquest delegate:self];
            if (theConnection) {
                self.errorSearchTextView.text = NSLocalizedString(@"BloodyHelp is updating your data.", @"updating location");
            } else {
                self.errorSearchTextView.text = NSLocalizedString(@"Conection error.\n", @"connection error updating");
            }
        }
    }];
}
还有很多,但是太长了。够了吗

编辑我把控制台拿出来:

Mar  1 22:08:26 iPad-de-xxx locationd[45] <Notice>: client 'com.appname' starting significant location changes
Mar  1 22:08:26 iPad-de-xxx awdd[3079] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Mar  1 22:08:26 iPad-de-xxx awdd[3079] <Error>: CoreLocation: CLClient is deprecated. Will be obsolete soon.
Mar  1 22:08:49 iPad-de-xxx awdd[3080] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Mar  1 22:08:49 iPad-de-xxx awdd[3080] <Error>: CoreLocation: CLClient is deprecated. Will be obsolete soon.
Mar  1 22:08:52 iPad-de-xxx appname copy[3078] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString appendString:]: nil argument'
    *** First throw call stack:
    (0x330262a3 0x3aebf97f 0x330261c5 0x32ff5773 0xfb85 0x3b2d711f 0x3b2d64b7 0x3b2db1bd 0x32ff9f3b 0x32f6cebd 0x32f6cd49 0x36b1f2eb 0x34e82301 0xd7c7 0x3b2f6b20)
Mar  1 22:08:52 iPad-de-xxxx ReportCrash[3082] <Notice>: Formulating crash report for process BloodyHelp copy[3078]
Mar  1 22:08:52 iPad-de-xxxxx com.apple.launchd[1] (UIKitApplication:com.appname[0x9e96][3078]) <Warning>: (UIKitApplication:com.appname[0x9e96]) Job appears to have crashed: Abort trap: 6
Mar  1 22:08:52 iPad-de-xxxxbackboardd[26] <Warning>: Application 'UIKitApplication:com.appname[0x9e96]' exited abnormally with signal 6: Abort trap: 6
Mar  1 22:08:52 iPad-de-Shimon ReportCrash[3082] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Mar  1 22:08:52 iPad-de-xxx ReportCrash[3082] <Notice>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/appname copy_2013-03-01-220852_iPad-de-xxxx plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0


*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString appendString:]: nil argument'
Mar 1 22:08:26 iPad de xxx位置D[45]:客户端'com.appname'开始发生重大位置变化
3月1日22:08:26 iPad de xxx awdd[3079]:libmobilegestart copySystemVersionDictionary值:无法从系统版本字典中查找ReleaseType
3月1日22:08:26 iPad de xxx awdd[3079]:CoreLocation:CLClient已弃用。很快就会过时。
3月1日22:08:49 iPad de xxx awdd[3080]:libmobilegestart copySystemVersionDictionary值:无法从系统版本字典中查找ReleaseType
3月1日22:08:49 iPad de xxx awdd[3080]:CoreLocation:CLClient已弃用。很快就会过时。
3月1日22:08:52 iPad de xxx appname副本[3078]:***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[\uu NSCFString appendString::]:nil参数'
***第一次抛出调用堆栈:
(0x330262a3 0x3aebf97f 0x330261c5 0x32ff5773 0xfb85 0x3b2d711f 0x3b2d64b7 0x3b2db1bd 0x32ff9f3b 0x32f6cebd 0x32f6cd49 0x36b1f2eb 0x34e82301 0xd7c7 0x3B2F6B220)
3月1日22:08:52 iPad de xxxx ReportCrash[3082]:为process BloodyHelp副本编制崩溃报告[3078]
3月1日22:08:52 iPad-de-xxxxx com.apple.launchd[1](UIKitApplication:com.appname[0x9e96][3078]):(UIKitApplication:com.appname[0x9e96])作业似乎已崩溃:中止陷阱:6
3月1日22:08:52 iPad de xxxxBackboardDD[26]:应用程序“UIKitApplication:com.appname[0x9e96]”异常退出,信号6:中止陷阱:6
3月1日22:08:52 iPad de Shimon ReportCrash[3082]:LibMobileGetStalt CopySystemVersionDictionary值:无法从系统版本字典中查找ReleaseType
3月1日22:08:52 iPad de xxx ReportCrash[3082]:已将crashreport保存到/var/mobile/Library/Logs/CrashReporter/appname copy\u 2013-03-01-220852\u iPad-de-xxxx plist,使用uid:0 gid:0,合成的\u euid:501 egid:0
***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[\u NSCFString appendString::]:nil参数'

我终于解决了这个问题,崩溃日志和控制台输出是找到错误的确切点并解决它的关键,问题不在location services,问题是在make gocoding之后,sub Adminarea为空,我试图附加到字符串,因为它的值为零,它抛出异常并关闭

解决方案就是创建这个

 NSString *subAdminArea = [NSString StringWithFormat:@"%d",place.subAdministrativeArea];
因此,如果place.subAdministrativeArea的值为零,则为“”字符串

建议:要解决此问题,请将设备连接到xcode,并在看到console out时发生错误,(您可以将“console标志”与NSLog放在一起,以了解错误的位置


谢谢!!

你有崩溃日志吗?还没有。我怎么能得到这些呢?从Xcode菜单栏-窗口->管理器,然后单击“设备”部分,然后单击左侧栏中设备附近的显示箭头,然后单击“设备日志”。请确保您的计算机上有应用程序包和dSYM,并且可通过聚光灯进行索引,以便您可以对其进行象征。您的应用程序是否真的命名为BloodyHelp?是的,它是真实名称
Mar  1 22:08:26 iPad-de-xxx locationd[45] <Notice>: client 'com.appname' starting significant location changes
Mar  1 22:08:26 iPad-de-xxx awdd[3079] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Mar  1 22:08:26 iPad-de-xxx awdd[3079] <Error>: CoreLocation: CLClient is deprecated. Will be obsolete soon.
Mar  1 22:08:49 iPad-de-xxx awdd[3080] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Mar  1 22:08:49 iPad-de-xxx awdd[3080] <Error>: CoreLocation: CLClient is deprecated. Will be obsolete soon.
Mar  1 22:08:52 iPad-de-xxx appname copy[3078] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString appendString:]: nil argument'
    *** First throw call stack:
    (0x330262a3 0x3aebf97f 0x330261c5 0x32ff5773 0xfb85 0x3b2d711f 0x3b2d64b7 0x3b2db1bd 0x32ff9f3b 0x32f6cebd 0x32f6cd49 0x36b1f2eb 0x34e82301 0xd7c7 0x3b2f6b20)
Mar  1 22:08:52 iPad-de-xxxx ReportCrash[3082] <Notice>: Formulating crash report for process BloodyHelp copy[3078]
Mar  1 22:08:52 iPad-de-xxxxx com.apple.launchd[1] (UIKitApplication:com.appname[0x9e96][3078]) <Warning>: (UIKitApplication:com.appname[0x9e96]) Job appears to have crashed: Abort trap: 6
Mar  1 22:08:52 iPad-de-xxxxbackboardd[26] <Warning>: Application 'UIKitApplication:com.appname[0x9e96]' exited abnormally with signal 6: Abort trap: 6
Mar  1 22:08:52 iPad-de-Shimon ReportCrash[3082] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Mar  1 22:08:52 iPad-de-xxx ReportCrash[3082] <Notice>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/appname copy_2013-03-01-220852_iPad-de-xxxx plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0


*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString appendString:]: nil argument'
 NSString *subAdminArea = [NSString StringWithFormat:@"%d",place.subAdministrativeArea];