I'm developing my own app, the iPhone version of this App is already on the Apple AppStore and now I'm working on the iPad version. Functionalities are (of course) nearly the same, but the user interface is different. The iPhone version is working fine.
Now I'm getting a strange error in XCode.
My app uses the SoundCloud API to stream some music and browse the songs of different users. On an iPhone I can display the small thumbnail images, because the ImageViews are pretty small (~40x40px).
But on my iPad, I need the bigger images, so I have to fetch the bigger artwork images and user avatars.
For that, I have two different methods. The first one fetches the bigger Artwork Image, the second one the bigger user avatar (profile picture).
- (NSURL *)bigCoverURLforTrack:(Track *)track {
if(track.coverURL) {
NSURL* coverURL = track.coverURL;
NSString* coverLarge = coverURL.absoluteString;
NSString* coverBig = [coverLarge stringByReplacingOccurrencesOfString:#"-large" withString:#"-t500x500"];
return [[NSURL alloc] initWithString:coverBig];
}
else return [[NSURL alloc] init];
}
- (NSURL*)bigAvatarURLforUser:(User*)user {
if(user.avatarURL) {
NSURL* avatarURL = user.avatarURL;
NSString* avatarLarge = avatarURL.absoluteString;
NSString* avatarBig = [avatarLarge stringByReplacingOccurrencesOfString:#"-large" withString:#"-t500x500"];
return [[NSURL alloc] initWithString:avatarBig];
}
else return [[NSURL alloc] init];
}
The first method is working fine, but the second one crashes each time.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteString]: unrecognized selector sent to instance
What am I doing wrong?
It must be that this line:
NSURL* avatarURL = user.avatarURL;
Is setting avatarURL to a string rather than an NSURL. Fix that at the source (make sure the method on user answers a real NSURL, not NSString), or force the type when you get it like this:
NSURL* avatarURL = [NSURL URLWithString:user.avatarURL];
Related
I am working on an app where I need to upload videos to server.Now here I have 2 things:
Shoot video using UIImagePickerController,generate a thumbnail and then upload to server
Pick video from Photos gallery, generate thumbnail and then upload to server.
Now the only difference between the two is:
When I use 'generateImageAsynchronouslyForTimes:completionHandler:' method,I get a call in its completionHandler block and I get an AVAsset.Now I am using below code to get its URL:
NSURL *path_url = [(AVURLAsset*)asset URL];
This is where I think things are getting messed up because I am getting something like this in case 2(when I pick video from gallery):
file:///var/mobile/Media/DCIM/102APPLE/IMG_2439.mp4
So I can't upload it while case 1 is is working fine.Is it something related to sandbox?
What's the difference between these 2 paths?
file:///private/var/mobile/Containers/Data/Application/DA4632E3-FA25-4EBE-9102-62495BF105BF/tmp/trim.07786CFE-2477-4146-9EA0-0A04042A8D05.MOV"
file:///var/mobile/Media/DCIM/102APPLE/IMG_2439.mp4
I guess its appSandbox path in 1)
In iOS, every app is like an island and there is a sandbox environment for it.So if you like to upload your video that is not in your sandbox,you will have to copy that video to your sandbox and then you can upload it.This is how you can do this:
NSURL *path_url = [(AVURLAsset*)asset URL];
PHAssetResource *asset_resource = [[PHAssetResource assetResourcesForAsset:[fetchResult lastObject]]firstObject];
PHAssetResourceRequestOptions *options = [PHAssetResourceRequestOptions new];
options.networkAccessAllowed = YES;
NSURL *newURL = [self getSandboxURLFromURL:path_url];
[[PHAssetResourceManager defaultManager] writeDataForAssetResource:asset_resource toFile:newURL options:options completionHandler:^(NSError * _Nullable error) {
//here you will get the newURL that you will use...
}];
//method to get sandbox URL
-(NSURL*)getSandboxURLFromURL:(NSURL*)photos_gallery_url{
NSString *last_path_component = [photos_gallery_url lastPathComponent];
NSString *pathToWrite = [NSTemporaryDirectory() stringByAppendingString:last_path_component];
NSURL *localpath = [NSURL fileURLWithPath:pathToWrite];
return localpath;
}
I am a newbie iOS learner. Couldn't find answer to following question after searching for a while. Hence, here it is.
Building on a first app that displays recent pictures from a user's instagram feed, I am trying to display pictures from the follows of that users instead.
To call recent pictures from the Instagram feed, which worked well, I had created the following method "imageForPhoto"
+ (void)imageForPhoto:(NSDictionary *)photo size:(NSString *)size completion:(void(^)(UIImage *image))completion {
if (photo == nil || size == nil || completion == nil) {
return;
}
NSString *key = [[NSString alloc] initWithFormat:#"%#-%#", photo[#"id"], size];
NSURL *url = [[NSURL alloc] initWithString:photo[#"images"][size][#"url"]];
[self downloadURL:url key:key completion:completion];
}
Therefore, I first modified my code to get the data related to the "follows" in my PhotosViewController instead of recent media pictures ( v1/users/3/follows ):
NSURLSession *session = [NSURLSession sharedSession];
NSString *urlString = [[NSString alloc] initWithFormat:#"https://api.instagram.com/v1/users/3/follows?count=99&access_token=%#", self.accessToken];
Then, I created a new method that I called friendAvatarForPhoto to get the follows profile pictures from a photo NSDictionary that is passed in as the only method parameter. I placed this method in my PhotoController class:
+ (void)friendAvatarForPhoto:(NSDictionary *)photo completion:(void(^)(UIImage *image))completion {
if (photo == nil || completion == nil) {
return;
}
NSString *key = [[NSString alloc] initWithFormat:#"avatar-%#", photo[#"user"][#"id"]];
NSURL *url = [[NSURL alloc] initWithString:photo[#"profile_picture"]];
[self downloadURL:url key:key completion:completion];
}
It seems to work. I have manually checked that the pictures that are rendered on my UICollectionView are actually coming from the "profile_picture" key of the responseDictionary I get back from Instagram.
Here is the structure of this dictionary: https://www.dropbox.com/s/ldjqupadqg0j3nq/friends_response_dictionary.png
Specifically, as you can see, I modified both the key and the url:
NSString *key = [[NSString alloc] initWithFormat:#"avatar-%#", photo[#"user"][#"id"]];
NSURL *url = [[NSURL alloc] initWithString:photo[#"profile_picture"]];
but I am not really understanding what I need to initial the *key string with... I kept "avatar" for example but why should I? I am pretty sure it's wrong although the result seems to be fine from what is returned on my UICollectionView.
What should I initiate this string with instead?
What is the function of this key in the overall NSURLSession process?
I'd love to better understand the overall process and better connect the dots with Instagram's API so I can query the right key and be sure I am getting what I am looking for. In a reliable way, not an intuitive one as I have just done app-arently.
Any help from experienced developers in the community would be welcome, I've just started to explore iOS dev a few weeks ago based on rusty C skills from a long time back.
Thank you!
:) Arsene
I don't know the reason but as soon as i get from a UITextField some data, like "Facebook", i call this code
- (IBAction)searchForAddress:(id)sender
{
[self loadRequestFromAddressField:_addressField];
}
- (void)loadRequestFromAddressField:(id)addressField
{
NSString *urlString = [addressField text];
[self loadRequestFromString:urlString];
}
- (void)loadRequestFromString:(NSString*)urlString
{
NSString *composedUrlString = [NSString stringWithFormat:#"http://www.google.com/search?q=%#",urlString];
NSURL *url = [NSURL URLWithString:composedUrlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:urlRequest];
}
Now the UIWebView loads correctly giving me the result of the google search, the problem is that when i try to enter some link it crashes giving me this error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WeBViewController searchURL:]: unrecognized selector sent to instance 0x8f38540'
What could be the problem??
Please check if your WeBViewController have methode name searchURL
it is very basic error.
It means you are calling method on instance of WeBViewController which is not implemented in it.
If you are still unable to fix this issue you can paste your code in question so we can take look at it.
I am trying to play audio and switch views with the same button..
- (IBAction)yourbuttonClicked:(UIButton *)sender
{
//start a background sound
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"tap2" ofType: #"caf"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath ];
myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
myAudioPlayer.numberOfLoops = -1; //infinite loop
[myAudioPlayer play];
//for Switch view
ViewController *nextView = [[ViewController alloc] initWithNibName:#"ViewController2"
bundle: Nil];
[self.navigationController pushViewController:nextView animated:YES];
}
2014-03-02 19:07:46.817 Balloon Tap[847:70b] * Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '* -[NSURL initFileURLWithPath:]: nil string
parameter'
When I launch my simulator and click on the play button that performs the action it crashes and in my log it comes up with this error above..
How do I go about fixing this and editing my code?
It appears soundFilePath is Nil
Try this
NSURL *url = [NSURL fileURLWithPath:stringPath];
This removes the alloc, which may cause you some issues here. Also I'm sure you've checked, but is there an issue with the filename? Does it actually exist in your bundle? I.e is it being compiled with the rest of your code? Make sure that you add that file to your project, and it appears in a "Copy Bundle Resources" build phase in your executable's target in Xcode.
Hi, I'm new to the iOS app development I have created an app with two ViewController for the the second controller have created on class in called video controll view. Everything is fine but when I click the play I'm getting warning like this I don't what is this can anyone please help me on that I'm stuck here for long time.
2013-12-25 10:10:12.890 politicalapp[346:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
This is the code I have put for the video player:
- (IBAction)play:(UIButton *)sender {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"d" ofType:#"mp4"]];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL: url];
[self presentMoviePlayerViewControllerAnimated:player];
player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;[player.moviePlayer play];
player = Nil;
}
#end
Your problem is that pathForResource is returning nil. There can be a number of causes of this. Try changing it to:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"d.mp4" ofType:nil]];
If that doesn't solve it, just search the multiple of questions on stackoverflow named "Path for resource returns nil" and trouble shoot based on the various issues already discussed.