I'm using Dragon mobile NDEV SDK, but I have a problem with recognition.
In the root view a button is here to start recording. User can select a row with voice in my table view and then my app push to the corresponding view. But in this view when user press record button again SKRecognizer returns always an empty array, in the second view and even in the first if user go back with back button.
I must restart app to use SKRecognizer again.
Same if I go straight to the second view and I use SKRecognizer, working on this view but if I navigate recognition is not working.
I have a dedicated class for Dragon recognizer, and I instantiate this class in each view with a property for each one.
- (IBAction)recordAction:(id)sender
{
if (_recognizer) {
[_recognizer release];
}
_recognizer = [[DragonRecognizer alloc] init];
[_recognizer startRecord];
}
And the SKRecognizer delegate:
- (void)recognizer:(SKRecognizer *)recognizer didFinishWithResults:(SKRecognition *)results
{
long numOfResults = [results.results count];
transactionState = TS_IDLE;
if (numOfResults > 0)
_result = [[results firstResult] lowercaseString];
[_recognizer release];
_recognizer = nil;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:DragonReconizerFinishWithResults object:nil];
}
I receive notification in the view controller:
- (void)stopRecordReconizer:(NSNotification *)n
{
if (![self.navigationController.visibleViewController isKindOfClass:[self class]])
return;
NSString *mainResult = [_recognizer result]; // No result
}
Do you know why SKRecognizer send me an empty array after second usage ?
Thanks for you're help !
Related
I'm looking through the code, specifically the Main View Controller that initiates calls with the call button. Both users must be on this View Controller after inputting their names to be found in a database.
But I'm confused as to how the callee is notified of a call and how it segues into a Calling View Controller that shows that they can answer or hangup.
I know that prepareForSegue sets the call to be whoever called, but I'm still confused with the remaining few lines after that.
So note the last two delegate methods: the first delegate method performs a segue, which makes sense. But what about the second one because I'm confused as to how it segues into call view controller that lets the callee answer or decline.
MainViewController.m
#import "MainViewController.h"
#import "CallViewController.h"
#import <Sinch/Sinch.h>
#interface MainViewController () <SINCallClientDelegate>
#end
#implementation MainViewController
- (id<SINClient>)client {
return [(AppDelegate *)[[UIApplication sharedApplication] delegate] client];
}
- (void)awakeFromNib {
self.client.callClient.delegate = self;
}
- (IBAction)call:(id)sender {
if ([self.destination.text length] > 0 && [self.client isStarted]) {
id<SINCall> call = [self.client.callClient callUserWithId:self.destination.text];
[self performSegueWithIdentifier:#"callView" sender:call];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
CallViewController *callViewController = [segue destinationViewController];
callViewController.call = sender;
}
#pragma mark - SINCallClientDelegate
// Outgoing Call?
- (void)client:(id<SINCallClient>)client didReceiveIncomingCall:(id<SINCall>)call {
[self performSegueWithIdentifier:#"callView" sender:call];
}
// Incoming Call?
- (SINLocalNotification *)client:(id<SINClient>)client localNotificationForIncomingCall:(id<SINCall>)call {
SINLocalNotification *notification = [[SINLocalNotification alloc] init];
notification.alertAction = #"Answer";
notification.alertBody = [NSString stringWithFormat:#"Incoming call from %#", [call remoteUserId]];
return notification;
}
(void)client:(id)client didReceiveIncomingCall:(id)call {
[self performSegueWithIdentifier:#"callView" sender:call];
}
is called when the app is in the foreground and an incoming call is in prgress, it will push the viewcontroller with teh call and since its direction is incoming you will be presented with an answer decline button,
(SINLocalNotification *)client:(id)client localNotificationForIncomingCall:(id)call {
SINLocalNotification *notification = [[SINLocalNotification alloc] init];
notification.alertAction = #"Answer";
notification.alertBody = [NSString stringWithFormat:#"Incoming call from %#", [call remoteUserId]];
return notification;
}
is called when the app is the background and you have enabled push
But what about the second one because I'm confused as to how it segues into call view controller that lets the callee answer or decline
The header explains to you what happens:
The return value will be used by SINCallClient to schedule ... a UILocalNotification. That UILocalNotification, when triggered and taken action upon by the user, is supposed to be used in conjunction with
-[SINClient relayLocalNotification:].
I would like to learn how to do an functional block of views.
For example:
I've got a book's list and I want to add a book with a button.
When I push the button --> Launch a Storyboard that it have a navigation controller with 2 or more views. (this create the Book object) and return it to the tableView.
The first table view will receive an object (Book) anymore.
Now, I used a view controller with:
+ (AddBookViewController *)sharedInstance {
static dispatch_once_t once;
static AddBookViewController * sharedInstance;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (id)init {
self = [super init];
if(self != nil) {
self = (AddBookViewController *)[[UIStoryboard storyboardWithName:#"AddBook" bundle:nil] instantiateInitialViewController];
}
return self;
}
- (void)showAddBookVCInController:(UIViewController *)hostVC completion:(AddBookCompletionHandler)completionHandler
{
self.compHandler =[completionHandler copy];
UINavigationController * navCtrl = [[UINavigationController alloc]initWithRootViewController:self];
//Show view!
[hostVC presentViewController:navCtrl animated:YES completion:^{
[self.tableView reloadData];
}];
Any idea or tutorial for this?
Thanks!
Sorry my bad english...
-(void)bookChosen:(Book *)bookObject
{
NSDictionary* userInfo = #{#"BOOK_KEY": #(bookObject)};
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:#"kBookChosenNotification" object:self userInfo:userInfo];
//here you will write pop if it is Navigation controller flow of presenting view
// OR
//here you will write dismissViewController.... if it was presented using flow of presenting view
}
in the view controller where you have list of fav books:
add this in viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receivedChosenBookNotification:) name:#"kBookChosenNotification" object:nil];
and implement method receivedChosenBookNotification like below
-(void) receivedChosenBookNotification:(NSNotification*)notification
{
if ([notification.name isEqualToString:#"kBookChosenNotification"])
{
NSDictionary* userInfo = notification.userInfo;
Book* bookObject = userInfo[#"BOOK_KEY"];
NSLog (#"Successfully received chosen book %#", bookObject);
}
}
i am not able to understand what you want to do after choosing book, i mean you want to dismiss or you want to pop. It depends on your flow of presenting/pushing view A >> B >>C. Its upto you but in any case you will be able to receive a book object in view controller A (or say it where you have list of fav books). Hope it helps
I've just implemented a commenting feature in my app. Ideally when someone leaves a comment, I'd like all notified people be able to swipe the push notification and open the app on that post.
I assume you want to open the concerned page directly. There are many ways to go about this, and it depends on how your app is laid out.
If you want to open an inner page upon app launch, you can programmatically trigger the segues that the user would otherwise need to make manually. (this ensures the back/home buttons work as opposed to loading the desired page directly).
Here's an excerpt from one of my own code, your use case may not be the same, but this is all i can do unless you give us more details.
- (BOOL) navigateToRespectiveSectionforPushNot:(NSDictionary*)pushNot
{
id rootVC = self.window.rootViewController;
NSLog(#"ROOT CLASS : %#", [rootVC class]);
if ([rootVC isKindOfClass:[SWRevealViewController class]])
{
NSLog(#"Root Class looking good... mission Navigate!!");
SWRevealViewController *homeVC = (SWRevealViewController*) rootVC;
NSString *category = [[pushNot objectForKey:pushPayloadKeyaps] objectForKey:pushPayloadKeyCategory];
NSString *subCat = [[pushNot objectForKey:pushPayloadKeyaps] objectForKey:pushPayloadKeySubCategory];
NSLog(#"category : %# , subcat : %#",category,subCat);
//The code for the page to which i'm supposed to navigate to is contained in the push notification payload
if ([category isEqualToString:pushCategoryItemChat])
{
[homeVC.rearViewController performSegueWithIdentifier:#"chatPush" sender:nil];
UINavigationController *nc = (UINavigationController*)homeVC.frontViewController;
NSLog(#"FrontView Class : %#",[nc.viewControllers[0] class]);
UITableViewController *tvc = (UITableViewController*)nc.viewControllers[0];
NSDictionary *send = #{chatPushTargetUserId:subCat,chatPushTargetUserName:#"",chatPushTargetUserImage:#""};
[tvc performSegueWithIdentifier:#"seguePushDemoVC" sender:send];
return YES;
}
//communityPush historyPush
else if ([category isEqualToString:pushCategoryItemCommunity])
{
if ([subCat isEqualToString:pushSubCatItemNewRequest])
{
[homeVC.rearViewController performSegueWithIdentifier:#"communityPush" sender:nil];
return YES;
}
else if ([subCat isEqualToString:pushSubCatItemAccepted])
{
[homeVC.rearViewController performSegueWithIdentifier:#"communityPush" sender:nil];
return YES;
}
}
else if ([category isEqualToString:pushCategoryItemHistory])
{
[homeVC.rearViewController performSegueWithIdentifier:#"historyPush" sender:nil];
return YES;
}
}
else
{
UIAlertView *whoa = [[UIAlertView alloc] initWithTitle:#"WHOA!!" message:#" That wasn't supposed to happen. You are not even logged in. Call 911..." delegate:nil cancelButtonTitle:#"mmKay.." otherButtonTitles:nil, nil];
[whoa show];
}
return NO;
}
I hope the code is self explanatory. cheers
In my app I have this hierarchy:
AppViewController (root)-->HUDViewController (as a container viewcontroller within AVC)-->NavBar (subview of UIView)-->UIButtons
When you touch some of the buttons they need to launch a UIPopoverController from AVC. I send a notification back from the NavBar class to AVC. In the selector for the notification center I have this code
...
//get the client list from the notification
[dictPopoverData setObject: [[notification userInfo] objectForKey:#"Client List"] forKey:#"Client List"];
//get the frame of the object launching the popover
popupCallerFrame = CGRectFromString([[notification userInfo] objectForKey:#"Caller Frame"]);
[self presentPopOver:CLIENT_LIST:YES:dictPopoverData];
...
then in presentPopOver I have this:
- (void) presentPopOver : (int) popoverID : (BOOL) isTable : (NSMutableDictionary*) dictPopoverData {
if (self.myPopoverController != nil) {
[self.myPopoverController dismissPopoverAnimated:YES];
self.myPopoverController = nil;
}
CGRect launchFrame;
//init the popover
if (popoverID == CLIENT_LIST) {
ClientListPopover* vcClientList = [[ClientListPopover alloc] initWithStyle:UITableViewStylePlain];
vcClientList.arrDataSource = [dictPopoverData objectForKey:#"Client List"];
self.myPopoverViewController = vcClientList;
//set the launch frame
launchFrame = popupCallerFrame;
launchFrame.origin.x = launchFrame.origin.x;
launchFrame.origin.y = launchFrame.origin.y + 100.0;
} else if (popoverID == PA_LIST) {
PAListPopover* vcPAList = [[PAListPopover alloc] initWithStyle:UITableViewStylePlain];
vcPAList.strClientNumber = [dictPopoverData objectForKey:#"Client Number"];
self.myPopoverViewController = vcPAList;
//set the launch frame
launchFrame = popupCallerFrame;
launchFrame.origin.x = launchFrame.origin.x;
launchFrame.origin.y = launchFrame.origin.y + 100.0;
}
//init and display the popover controller
if (self.myPopoverController == nil) {
//add the self.myPopoverViewController
self.myPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.myPopoverViewController];
//display the popover
[self.myPopoverController presentPopoverFromRect:launchFrame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
[self.myPopoverController setDelegate:self];
} else {
[self.myPopoverController dismissPopoverAnimated:YES];
self.myPopoverController = nil;
}
}
So what is suppose to happen is the user clicks the client button, notification gets sent to AVC, a UITable in a popover controller is presented. The user then selects a client from the table. Again, a notification is sent to AVC, the displayed client list popover should now be dismissed and the PA list popover should show. It seems that [self.myPopoverController dismissPopoverAnimated:YES] is not being called. I've traced it and it hits that line of code but nothing happens, the first popover remains on the screen. Any ideas of what I am doing wrong?
Edit: I forgot to mention I can't seem to assign a delegate to self.myPopoverController. Which is probably why the dismiss method is not firing.
Edit: I added the call to the delegate after the popover controller is inited. That didn't seem to make a difference. If I touch outside the first popover, without touching inside, it does dismiss and I can trace the method.
We are implementing one web based application in iPhone. if i answered the incoming phone call my application is relaunching once again instead of resume the application to the state where it last the focus.
we are implementing stack of views. I.e i am maintaining views in a stack manner and each view has the information like images and text information, if i am in 3rd or 4th view, if i answered the incoming phone call my application is relaunching and it is showing 1st view only.
Please tell me how to resume to the 4th view level.
Unfortunately the iPhone doesn't do very much to help you here. I can't guarantee that this will be useful for you but this is how I do it.
In my app I have the following protocol:
#protocol SaveState
- (NSData*) saveState;
- (id) initWithSaveState:(NSData*)data;
#end
Any UIViewController that I need to be able to save its state implements it.
In applicationWillTerminate: I have the following code:
for (UIViewController* vc in self.navigationController.viewControllers) {
if ([vc conformsToProtocol:#protocol(SaveState)]) {
NSArray* state = [NSArray arrayWithObjects:NSStringFromClass([vc class]), [(UIViewController<SaveState>*)vc saveState], nil];
[vcList addObject:state];
}
}
I then save vcList to the NSUserDefaults. To restore the state I have this in applicationDidFinishLaunching::
for (NSArray* screen in screenList) {
UIViewController<SaveState>* next = [[NSClassFromString([screen objectAtIndex:0]) alloc] initWithSaveState:([screen count] == 2) ? [screen objectAtIndex:1] : nil];
if (next != nil) {
[[self navigationController] pushViewController:next animated:NO];
[next release];
}
else {
// error handling
}
}
See Apple's DrillDownSave sample - it demonstrates how to do that.