Airdrop: not able to see nearby devices - ios7

I'm trying to implement Airdrop feature in my app but I'm not able to see any nearby device even if Airdrop is enabled on both the e the devices. But if I go to Safari/Mail or any other app to use Airdrop, then the devices start appearing everywhere (INCLUDING MY APP also). I'm using the following code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"Untitled" ofType:#"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSData *data = [NSData dataWithContentsOfURL:url];
NSArray *arr = [NSArray arrayWithObject:data];
UIActivityViewController *actVC = [[UIActivityViewController alloc] initWithActivityItems:arr applicationActivities:nil];
[self presentViewController:actVC animated:YES completion:nil];
Below is the image showing the no devices are detected.
I'm not getting what may be the problem for this. Do I need to have some specific settings in my app so that I can see near-by devices without using Safari or any other app.

Related

Caching and saving videos in tableview

I'm displaying videos with tableview and would like to save urls/data in cache so user won't have to download the same video again when replayed.
However I'd like to keep them only until user quits the app. The next time he opens the app he'll have to download them again so I only need to save them for the app's active lifetime.
Should I still do caching or is there a more efficient way to do this?
-(void)loadVideo:(NSString *)urlString {
NSURL *url = [NSURL URLWithString:urlString];
NSString* cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* file = [cachePath stringByAppendingPathComponent:#"/EGOCache.plist"];
NSDictionary *dict =[NSDictionary dictionaryWithContentsOfFile:file];
if ([dict objectForKey:urlString] )
{
NSData *data = [[EGOCache globalCache] dataForKey:urlString];
data = [NSURLConnection sendSynchronousRequest:
[NSURLRequest requestWithURL:url]
returningResponse:nil
error:nil];
NSLog(#"loading from cache %#",urlString);
}else{
NSData *data = [NSURLConnection sendSynchronousRequest:
[NSURLRequest requestWithURL:url]
returningResponse:nil
error:nil];
[[EGOCache globalCache] setData:data forKey:urlString];
NSLog(#"saving cache %#",urlString);
}
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 10.0];
[self.videoPlayer setContentURL:[request URL]];}
AVFoundation allows for streaming a video file on disk.
I suggest you look into saving the video in the Documents folder or Caches folder and steam it to AVFoundation from there. Then when the user quits the app, applicationWillTerminate gets called and you can wipe the videos from disk.
EDIT
Using MPMoviePlayerController:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: URL-TO-FILE-ON-DISK];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];

AVAudioPlayer or PlaySystemSoundID?

I have an iOS app which is going to provide a sound pad for the user - i.e. when they tap a button a short sound clip is played.
At the moment, the app is designed around using SystemSoundID.
Would it now be advised to use AVAudioPlayer now over this? If so, what would be the ideal code to use? Would it be the standard:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"yoursoundfile"
ofType:#"mp3"]];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:url
error:nil];
[audioPlayer play];

going for the next youtube video in my iphone app

i'm developing an iphone app which can play youtube links using a web view
Every things fine. but except it goes to the next video automatically. is thr any way to stop this.
Here is my code.
NSString *urlAddress = #"http://www.youtube.com/embed/wh0ZK5QJMWk"; //http://www.youtube.com/embed/wh0ZK5QJMWk
NSURL *url = [[[NSURL alloc] initWithString:urlAddress] autorelease];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
Thanks

How to play system button click sound on iPad?

I need to play some system sound when users click button in my application which is running on iPad. How to implement it in iOS?
If you want to play a short sound (shorter than 30 sec), you can do it easily like this:
Note: You'll have to add AudioToolbox framework and import it (#import <AudioToolbox/AudioToolbox.h>)
SystemSoundID mySSID;
NSString *path = [[NSBundle mainBundle] pathForResource:#"beep" ofType:#"wav"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: path], &mySSID);
AudioServicesPlaySystemSound(mySSID);
Also note that the file can be:
No longer than 30 seconds in duration
In linear PCM or IMA4 (IMA/ADPCM) format
Packaged in a .caf, .aif, or .wav file
You should use AVAudioPlayer.
There's a great tutorial here on using AVAudioPlayer to play sounds. A very simple example of it's use:
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/audiofile.mp3",dataPath];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];
NSString *path = [[NSBundle mainBundle] pathForResource:#"gorilla 2" ofType:#"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];

AVPlayer Can't Play

I want to play a remote mp3 with AVPlayer. I can't make it work and I can't see the reason why it doesn't work. Code:
NSString *urlstr=#"..some link to a mp3"
NSURL *url=[NSURL URLWithString:urlstr];
self.player = [[[AVPlayer alloc] initWithURL:url] retain];
[player play];
The link is valid. If I load it in a webView it plays right away.
Please help.
I have get a solution. Please try the following code:
NSString *urlstr=#"http://www.3rdeyelab.com/mp3/mp3/tailtoddle_lo.mp3"
NSURL *url=[NSURL URLWithString:urlstr];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
player = [[AVPlayer playerWithPlayerItem:playerItem] retain];
[player play];
player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
Hope it will work for you!!!
If you use a local link as URL, so you should initiate url with fileURLWithPath method:
NSURL *url = [NSURL fileURLWithPath:urlstr];
The NSURLConnection class, regardless of whether the URL is local or remote, should always be used whenever a URL is concerned. It's the only thread-safe, non-intrusive means of loading a AVPlayerItem or AVAsset. Remember: your app shares the iPhone with other apps; and, this is the way to be responsible insodoing.