我的应用程序在[NSPlaceholderString initWithString:]:nil参数错误的情况下继续崩溃(见代码)

时间:2017-01-02 18:39:47

标签: objective-c xcode

我的应用程序在以下位置(请参阅代码)一直崩溃并显示错误:

  

[NSPlaceholderString initWithString:]:nil参数。

登录后,如果成功,则应将视频下载到我的网站。这是正常工作,直到我升级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];


}

1 个答案:

答案 0 :(得分:0)

从这一行调用了这个问题

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

我认为键是&#34; user_id&#34;返回nil对象。如果您尝试代码

[[NSString alloc] initWithString:nil];

你最终会遇到同样的错误。