我的应用程序在以下点(请参阅代码)不断崩溃,并显示 [NSPlaceholderString initWithStrin



我的应用程序在以下点(请参阅代码)不断崩溃并显示错误:

[NSPlaceholderString initWithString:]: nil argument.

登录后,如果成功,它应该将视频下载到我的网站。在我升级Xcode版本之前,这一直工作正常。谁能告诉我代码可能出了什么问题或为什么开始发生?

这是我的代码:

- (IBAction)addBtnClicked:(id)sender {
    NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
    if (![standardDefaults objectForKey:@"login"]) {
        [[[UIAlertView alloc] initWithTitle:@"Hi" message:@"You need an account before you can do that. Register now or Sign In if your an existing member:)" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Sign In",@"No Thanks", nil] show];
    }
    else{
        NSString *strLogin = [[NSString alloc] initWithString:[standardDefaults objectForKey:@"login"]];
        if (![strLogin isEqualToString:@"yes"])
        {
            [[[UIAlertView alloc] initWithTitle:@"Hi there" message:@"You need an account before you can do that. Register now for free :)" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Register",@"No Thanks", nil] show];
        }
//I believe it is crashing at this point ---
        for (int i = 0; i < [self.urlArray count]; i++) {
            NSLog(@"URLcount is %lu",(unsigned long)[self.urlArray count]);
            videoURL = [self.urlArray objectAtIndex:i];
            [self saveToCameraRoll];
        }
    }
}
Here is my saveToCameraRoll
- (void) saveToCameraRoll {
    [self showProgressHud];
    videodata= [[NSData alloc] init];
    NSDate *date = [NSDate date];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
    [dateFormat setDateFormat:@"MM-dd-yyyy hh:mm"];
    strDate = [dateFormat stringFromDate:date];
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    NSLog(@"videoURL is is is is %@",videoURL);
    UISaveVideoAtPathToSavedPhotosAlbum(videoURL.path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
    videodata = [NSData dataWithContentsOfURL:videoURL];

    NSRange needleRange = NSMakeRange([videoURL.path length]- 21, 21);
    filename = [videoURL.path substringWithRange:needleRange];
    NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
    NSString *strId = [[NSString alloc] initWithString:[standardDefaults objectForKey:@"user_id"]];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://mywebsite.com/video-save.php"]]];
    [request setPostValue:strId forKey:@"userid"];
    [request setPostValue:@"2015-04-18 : 16:00" forKey:@"date"];
    [request setData:videodata  forKey:@"videofile"];

    [request addRequestHeader:@"Content-Type" value:@"application/json"];
    [request addRequestHeader:@"Accept" value:@"application/json"];
    [request setDelegate:self];
    [request setTimeOutSeconds:60.0];
    [request setRequestMethod:@"POST"];
    [request startAsynchronous];

}

问题是从这一行调用

NSString *strId = [[NSString alloc] initWithString:[standardDefaults objectForKey:@"user_id"]];

我认为键@"user_id"返回nil对象。 如果您尝试代码

[[NSString alloc] initWithString:nil];

您最终会遇到相同的错误。

最新更新