After app open, and Press ON BLE Device.
centralManagerDidUpdateState function is working.
CBUUID *uuid = [CBUUID UUIDWithString:#"8A1FEA41-3A2F-7860-568D-2325D6C31C91"];
NSArray *services = [NSArray arrayWithObjects:uuid, nil];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
[central scanForPeripheralsWithServices:services options:options];
Would not call to didDiscoverPeripheral: function.
-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{
}
But if call nill value to scanForPeripheralsWithServices than will call to didDiscoverPeripheral: function.
[central scanForPeripheralsWithServices:nil options:options];
What is issue? Please.
Related
I can record with the setup below - it works first time, but then when I try again the file is always 8192 bytes, i.e. not a correct recording.
-(void) startRecording
{
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 11025.0f], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithInt: 2], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityLow], AVEncoderAudioQualityKey,
nil];
NSString *filenameBasedOnTime = [[NSDate date] description];
if (_recordedFileURL) _recordedFileURL = nil;
_recordedFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:filenameBasedOnTime]];
NSError* error;
if (_audioRecorder) _audioRecorder = nil;
_audioRecorder = [[AVAudioRecorder alloc] initWithURL:_recordedFileURL settings:settings error:&error];
_audioRecorder.delegate = self;
if (error)
{
return;
}
[_audioRecorder prepareToRecord];
_audioRecorder.meteringEnabled = YES;
[_audioRecorder record];
}
-(void) stopRecord
{
[_audioRecorder stop];
}
- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{
[self saveRecording];
}
-(void) saveRecording
{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_recordedFileURL.relativeString]];
NSLog(#"Recording data size = %i", [data length]);
}
It is called inside a UIPopoverController if that helps...
Since found out that the problem was I was missing
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:NULL];
From here iPhone SDK: AVAudioRecorder will not record after calling [AVPlayer play]
I'm working on 'deep linking' a Facebook request into my iOS app. A Facebook app is setup and seems to work as I can send a request to a friend, the request badge appears in the friend's Facebook, and clicking on the request launches my app (all on the iPhone).
However, so far I could not pass any data with the request, which I want to use when my app launched from the Facebook app with the request.
I use the following call:
-(void) fbRequestActionWithMessage: (NSString *) message andLink: (NSString *) link
{
NSDictionary *requestData = [NSDictionary dictionaryWithObjectsAndKeys:
#"data1", #"key1",
#"data2", #"key2",
nil];
NSString *requestDataString = [requestData JSONRepresentation];
NSMutableDictionary* params = [NSMutableDictionary
dictionaryWithObjectsAndKeys:
message, #"message",
#"Check this out", #"notification_text",
link, #"link",
requestDataString, #"data",
nil];
[facebook dialog:#"apprequests" andParams:params andDelegate:self];
}
Neither the "data" nor the "link" values in the params dictionary seem to have any effect. Ideally, when my app is launched from this request, I would get back the "data" or the "link" values. Can this be done?
I could not find any Facebook docs about the structure of params dictionary - is there a list of supported keys and their effect?
The "link" parameter and "notification_text" is not supported in iOS but you should be able to pass in data and get it back.
Example, passing in data:
FBSBJSON *jsonWriter = [FBSBJSON new];
NSDictionary *requestData = [NSDictionary dictionaryWithObjectsAndKeys:
#"data1", #"key1",
#"data2", #"key2",
nil];
NSString *requestDataString = [jsonWriter stringWithObject:requestData];
NSMutableDictionary* params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
message, #"message",
requestDataString, #"data",
nil];
[facebook dialog:#"apprequests"
andParams:params
andDelegate:self];
Example, reading it back:
....
#property (nonatomic, retain) NSURL *openedURL;
....
#synthesize openedURL = _openedURL;
....
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
self.openedURL = url;
return [FBSession.activeSession handleOpenURL:url];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSession.activeSession handleDidBecomeActive];
if (FBSession.activeSession.isOpen) {
[self checkIncomingNotification];
}
}
- (void) notificationGet:(NSString *)requestid {
[FBRequestConnection startWithGraphPath:requestid
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (!error) {
NSString *title;
NSString *message;
if ([result objectForKey:#"data"]) {
// Process data in request
FBSBJSON *jsonParser = [FBSBJSON new];
NSDictionary *requestData =
[jsonParser
objectWithString:[result objectForKey:#"data"]];
[NSString stringWithFormat:#"Badge: %#, Karma: %#",
NSString *data1 = [requestData objectForKey:#"key1"];
NSString *data2 = [requestData objectForKey:#"key2"];
}
}
}];
}
- (void) checkIncomingNotification {
if (self.openedURL) {
NSString *query = [self.openedURL fragment];
if (!query) {
query = [self.openedURL query];
}
NSDictionary *params = [self parseURLParams:query];
// Check target URL exists
NSString *targetURLString = [params valueForKey:#"target_url"];
if (targetURLString) {
NSURL *targetURL = [NSURL URLWithString:targetURLString];
NSDictionary *targetParams = [self parseURLParams:[targetURL query]];
NSString *ref = [targetParams valueForKey:#"ref"];
// Check for the ref parameter to check if this is one of
// our incoming news feed link, otherwise it can be an
// an attribution link
if ([ref isEqualToString:#"notif"]) {
// Get the request id
NSString *requestIDParam = [targetParams
objectForKey:#"request_ids"];
NSArray *requestIDs = [requestIDParam
componentsSeparatedByString:#","];
// Get the request data from a Graph API call to the
// request id endpoint
[self notificationGet:[requestIDs objectAtIndex:0]];
}
}
// Clean out to avoid duplicate calls
self.openedURL = nil;
}
}
You can find more details on this, using the latest SDK v3.1:
https://developers.facebook.com/docs/howtos/send-requests-using-ios-sdk/
problem: cannot record sound after streaming audio over http.
The problem which I am having is that I can no longer record sound after streaming mp3 using this guide: http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html
I can record sound perfectly fine before i stream any mp3. only after i stream mp3 using the guide that my ios app can no longer record sound.
I was wondering if any of you might have run into this issue before or have any hunch of why this problem occur? I'll go ahead and post my code for recording, just in case any of you would need to look at it.
before i stream any mp3, audioRecorderDidFinishRecording always fire after a record has been done.
after i stream mp3, audioRecorderDidFinishRecording never fire after a record has been done.
Thank you in advance for your help.
// #########################
NSURL *soundFileUrl = [NSURL fileURLWithPath:self.recordFilePath];
NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithInt:AVAudioQualityMax], AVEncoderAudioQualityKey,
[NSNumber numberWithInt:24], AVEncoderBitRateKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSNumber numberWithFloat:22050.0f], AVSampleRateKey,
nil];
NSError *error = nil;
self.recorder = [[AVAudioRecorder alloc] initWithURL:soundFileUrl settings:recordSettings error:&error];
if (error) {
NSLog(#"%#", error);
} else{
self.recorder.delegate = self;
[self.recorder prepareToRecord];
[self.recorder record];
self.recordCountdown = [NSTimer scheduledTimerWithTimeInterval:(1.0/1.0) target:self selector:#selector(updateLabelCountdown) userInfo:nil repeats:YES];
}
// delegate for finish recording with success and failure
- (void) audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag {
NSLog(#"record did finish flag - %d", flag);
}
- (void) audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error {
NSLog(#"error record - %#", [error localizedDescription]);
}
Try this
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
reference iPhone SDK: AVAudioRecorder will not record after calling [AVPlayer play]
i've checked several posts on the internet and stackOverflow but couldn't find an answer so far. This is my AppDelegate, as far as I know, those implementations are pretty standard.. i just added the following line and passed the arguments, but it didn't help..
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
I cleaned my project, that didn't help either. Also the ApplicationSupport folder does not get created. Is it possible that this is the cause of the problem? I didn't create the App with the option "use core data", but I provided the the necessary methods...
-(NSPersistentStoreCoordinator *)persistentStoreCoordinator{...} is at the bottom!
Help is greatly appreciated!
#import "WebLogClientAppDelegate.h"
// create anonymous catergories for uses in this class
#interface WebLogClientAppDelegate();
#property(nonatomic, readonly) NSString *applicationSupportFolder;
#property(nonatomic, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
#end
#implementation WebLogClientAppDelegate
#synthesize autorPrefFeld, benutzerPrefFeld, passwortPrefFeld, hauptfenster,
managedObjectModel, managedObjectContext, autor;
- (void) applicationWillFinishLaunching:(NSNotification *)notification
{
NSLog(#"applicationWillFinishLaunching");
NSDictionary *defaultsDict = [NSDictionary dictionaryWithObjectsAndKeys:#"Mathias Mustermann", #"autor",
#"mathias", #"benutzer",
#"passwort",#"passwort", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDict];
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
[moc commitEditing];
if ([moc hasChanges]) {
NSLog(#"Save needed!");
[moc save:nil];
}
return NSTerminateNow;
}
- (NSString *)autor{
return [[NSUserDefaults standardUserDefaults] stringForKey:#"autor"];
}
- (void)windowDidBecomeKey:(NSNotification *)notification
{
NSLog(#"windowDidBecomeKey");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[autorPrefFeld setStringValue:[defaults stringForKey:#"autor"]];
[benutzerPrefFeld setStringValue:[defaults stringForKey:#"benutzer"]];
[passwortPrefFeld setStringValue:[defaults stringForKey:#"passwort"]];
}
- (void)windowDidResignKey:(NSNotification *)notification
{
NSLog(#"windowDidResignKey");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[autorPrefFeld stringValue] forKey:#"autor"];
[defaults setObject:[benutzerPrefFeld stringValue] forKey:#"benutzer"];
[defaults setObject:[passwortPrefFeld stringValue] forKey:#"passwort"];
[defaults synchronize];
}
- (NSManagedObjectModel *)managedObjectModel
{
if(objectModel){
return objectModel;
}
objectModel= [NSManagedObjectModel mergedModelFromBundles:nil];
return objectModel;
}
- (NSString *)applicationSupportFolder
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : NSTemporaryDirectory();
return [basePath stringByAppendingPathComponent:#"WeblogClient"];
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (storeCoord) {
return storeCoord;
}
NSFileManager *fileManager;
NSString *applicationSupportFolder;
NSURL *url;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
fileManager = [NSFileManager defaultManager];
applicationSupportFolder = self.applicationSupportFolder;
if (![fileManager fileExistsAtPath:applicationSupportFolder]) {
[fileManager createDirectoryAtPath:applicationSupportFolder withIntermediateDirectories:NO attributes:nil error:nil];
}
url = [NSURL fileURLWithPath:[applicationSupportFolder stringByAppendingPathComponent:#"WeblogClient.xml"]];
storeCoord = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel];
[storeCoord addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:options error:nil];
return storeCoord;
}
- (NSManagedObjectContext *)managedObjectContext
{
if (moc) {
return moc;
}
NSPersistentStoreCoordinator *coordinator = self.persistentStoreCoordinator;
if (coordinator) {
moc = [NSManagedObjectContext new];
[moc setPersistentStoreCoordinator:coordinator];
}
return moc;
}
#end
Not sure if you fixed your error, but check out: I keep on getting "save operation failure" after any change on my XCode Data Model
Also for me, I had the same storecordinator sqlite name as another project I was working on and had already ran...
I am trying to setup a basic controller that will record user audio input(voice). However, the AVAudioRecorder's prepareToRecord method is failing and I can't figure out why. I have setup the audio session in my app delegate and I do not receive an errors when I instantiate the AVAudioRecorder instance:
// App delegate snippet
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
NSError* audioSessionError = nil;
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord
error: &audioSessionError];
if (audioSessionError) {
NSLog (#"Error setting audio category: %#", [audioSessionError localizedDescription]);
} else {
NSLog(#"No session errors for setting category");
}
[audioSession setActive:YES error:&audioSessionError];
if (audioSessionError) {
NSLog (#"Error activating audio session: %#", [audioSessionError localizedDescription]);
} else {
NSLog(#"no session errors for setActive");
}
// VIEW DID LOAD IN RECORDERCONTROLLER
- (void)viewDidLoad {
self.navigationItem.title = [NSString stringWithFormat:#"%#", [[MyAppDelegate loadApplicationPlist] valueForKey:#"recorderViewTitle"]];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:#selector(dismiss)];
[self alertIfNoAudioInput];
[self createAVAudioRecorder];
minutesSecondsFormatter = [[SimpleMinutesSecondsFormatter alloc] init];
currentTimeUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self selector:#selector(updateAudioDisplay)
userInfo:NULL repeats:YES];
[super viewDidLoad];
}
// CREATE AVAUDIORECORDER
- (NSError *)createAVAudioRecorder {
NSError *recorderSetupError = nil;
[audioRecorder release];
audioRecorder = nil;
NSString *timestamp = [NSString stringWithFormat:#"%d", (long)[[NSDate date] timeIntervalSince1970]];
NSString *destinationString = [[MyAppDelegate getAppDocumentsDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.caf", timestamp]];
NSLog(#"destinationString: %#", destinationString);
NSURL *destinationUrl = [NSURL fileURLWithPath: destinationString];
audioRecorder = [[AVAudioRecorder alloc] initWithURL:destinationUrl
settings:[[AVRecordSettings sharedInstance] getSettings]
error:&recorderSetupError];
if (recorderSetupError) {
UIAlertView *cantRecordAlert =
[[UIAlertView alloc] initWithTitle:#"Can't record"
message:[recorderSetupError localizedDescription]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[cantRecordAlert show];
[cantRecordAlert release];
return recorderSetupError;
} else {
NSLog(#"no av setup error");
}
if ([audioRecorder prepareToRecord]) {
recordPauseButton.enabled = YES;
audioRecorder.delegate = self;
} else {
NSLog(#"couldn't prepare to record");
}
NSLog (#"recorderSetupError: %#", recorderSetupError);
return recorderSetupError;
}
The prepareToRecord also fails (silently, without an error) if the directory where you try to save the file doesn't exist. Use NSFileManager to check if the directory already exists.
It is failing because you did not initialize the AVAudioRecorder object using proper settings. Do this before initializing it:
NSDictionary *recordSettings =
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
then you can instantiate it using
audioRecorder = [[AVAudioRecorder alloc] initWithURL:destinationUrl
settings:recordSettings
error:&recorderSetupError];