How to Use Speech-To-Text library in my Xcode project? - iphone

I want to use speech to text library in my Xcode project. I added successfully the 'Speech-To-Text' library to my Xcode project and i imported header files into my application. I use the following code but nothing will happen.I can't get any view.
#import "SineWaveViewController.h"
SineWaveViewController *sineWav = [[SineWaveViewController alloc]init];
[self.navigationController pushViewController:sineWav animated:YES];

- (id)init {
self = [super init];
if (self) {
NSArray *cmds = [NSArray arrayWithObjects:#"Sing", #"Jump", #"Roll over", nil];
recog = [[NSSpeechRecognizer alloc] init]; // recog is an ivar
[recog setCommands:cmds];
[recog setDelegate:self];
}
return self;
}

Related

Ios MFMailComposeViewController not displaing

I trying to write rhodes native extension extension for opening iOS MailComposer.
Now code "works", but MFMailComposeViewController not displaying and xcode shows warning:
Attempt to present <MFMailComposeViewController: 0x12b60840> on <Iosmailto: 0xc1898d0> whose view is not in the window hierarchy!
I read that UIViewControllers must be in hierarchy, but i can't provide this from Rhodes ruby code or clear-C extension wrapper.
Now i'm trying to present my UIViewController with MFMailComposeController from [UIApplication sharedApplication].keyWindow.rootViewController but mail composer not show yet.
interface from iosmailto.h:
#interface Iosmailto : UIViewController<MFMailComposeViewControllerDelegate>
{
}
#property(nonatomic, assign) id delegate;
//-(IBAction)send_mail:(id)sender;
#end
implementation from iosmailto.m:
#implementation Iosmailto
- (void)viewDidLoad {
[super viewDidLoad];
[self send_mail];
}
- (void)send_mail {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
[composer setSubject:[NSString stringWithUTF8String:subj]];
NSArray *recipients_array = [NSArray arrayWithObject:[NSString stringWithUTF8String:recipients]];
[composer setToRecipients:recipients_array];
NSString *composerBody = [NSString stringWithUTF8String:message];
[composer setMessageBody:composerBody isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:composer animated:YES];
[composer release];
} else {
NSLog(#"Device is unable to send email in its current state.");
}
}
/* some unnecessary for this question methods */
#end
And C function defined in iosmailto.m thats called from Rhodes:
// find root vc
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
// find topmost vc
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
iosmailer = [[Iosmailto alloc] init];
iosmailer.delegate = topController;
[topController presentViewController:iosmailer animated:YES completion:nil];
This app is not for AppStore. Hacks is welcome if needed.
Update init for Iosmailto:
- (id)init
{
self = [super initWithNibName:nil bundle:nil];
return self;
}
Update 2 The short version of this code (without UIViewController wrapper) was my starting point. That's don't work too. And this have the same warning and one more:
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = (id<MFMailComposeViewControllerDelegate>)topController ;
[composer setSubject:[NSString stringWithUTF8String:subj]];
NSArray *recipients_array = [NSArray arrayWithObject:[NSString stringWithUTF8String:recipients]];
[composer setToRecipients:recipients_array];
NSString *composerBody = [NSString stringWithUTF8String:message];
[composer setMessageBody:composerBody isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[topController presentModalViewController:composer animated:YES];
[composer release];
} else {
}
Use this code to present view controller
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:composer
animated:YES
completion:nil];
Ok I think the problem is that your UIViewController doesn't have anything in its view property because you aren't using a .xib file to initialize it. See this question which programmatically creates a UIView and assigns it to the UIViewController's view property. I think that's the right way to go. See the implementation of their -(void)loadView method.
Your use-case is also a little strange, since it looks like your Iosmailto UIViewController doesn't have any content, and you're just using it as a wrapper around MFMailComposeViewController--you might consider reimplementing your C method to directly create a MFMailComposeViewController without the unnecessary layer of indirection of this unnecessary UIViewController that doesn't display anything itself.

GADInterstitial custom ads not working

i have a problem in getting the GADInterstitial custom ads i have tried this code
if(nil != m_pBannerView)
{
m_pBannerView.delegate = nil;
[m_pBannerView release];
m_pBannerView = nil;
}
m_pBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
m_pBannerView.delegate = self;
m_pBannerView.rootViewController = self;
m_pBannerView.adUnitID = #"AdMob Publisher ID";
m_pBannerView.rootViewController = self;
[self.view addSubview:m_pBannerView];
GADRequest *request = [GADRequest request];
request.testing = YES;
[m_pBannerView loadRequest:request];
if(nil != m_pInterstitial)
{
[m_pInterstitial release];
m_pInterstitial = nil;
}
m_pInterstitial = [[GADInterstitial alloc] init];
m_pInterstitial.delegate = self;
m_pInterstitial.adUnitID = #"INTERSTITIAL_AD_UNIT_ID";
GADRequest *interstialRequest = [GADRequest request];
interstialRequest.testing = YES;
[m_pInterstitial loadRequest: interstialRequest];
}
And in GADInterstitial Delegates i am calling [ad presentFromRootViewController:self];
but still i am not able to get the custom ads please help me.
You have to use your own unique id for adUnitID property
GADInterstitial is an interesting way to show ads in your Apps, and kind of a tricky one too. Following this example, lets pursue the following steps:
First we need to set up the environment for them to show at all.
Download the GoogleAdMobAdsSdkiOS, preferably the latest. Add
the SDK to your project, but do remember to delete the example
Projects in the AddOns folder in the SDK.
Next, add the following frameworks in your Project>>Build
Phases>>Link Binary With Libraries:
AdSupport.framework (select Optional if catering for < iOS7)
StoreKit.framework
CoreData.framework
CoreAudio.framework
AVFoundation.framework
MessageUI.framework
AudioTool.framework
libGoogleAdMobAds.a (placed in the SDK folder)
The basics are complete. Now we need to select the ViewController we wish to see our Ads in. So here's some code, here we import the header for GADInterstitialDelegate and extend it with our MainViewController.h:
#import "GADInterstitialDelegate.h"
#define kSampleAdUnitID #"/6253334/dfp_example_ad/interstitial"
#class GADInterstitial;
#class GADRequest;
#interface MainViewController : UIViewController<GADInterstitialDelegate>
{
BOOL isLoaded_;
NSTimer *quickie_;
}
#property(nonatomic, strong) GADInterstitial *interstitial;
//Make sure the delegate is handled properly.
Now we need to move to the implementation i.e. in MainViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// FOLLOW THE CODE BELOW FOR ADMOD INTERESTIAL IMPLEMENTATION
[self initializeAds];
quickie_ = [[NSTimer alloc] init];
quickie_ = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(showAdd) userInfo:nil repeats:YES];
}
-(void)showAdd
{
if(isLoaded_ && [quickie_ isValid])
{
[quickie_ invalidate];
quickie_ = nil;
[self.interstitial presentFromRootViewController:self];
}
}
- (GADRequest *)request
{
GADRequest *request = [GADRequest request];
return request;
}
-(void)initializeAds
{
// Create a new GADInterstitial each time. A GADInterstitial will only show one request in its
// lifetime. The property will release the old one and set the new one.
self.interstitial = [[GADInterstitial alloc] init];
self.interstitial.delegate = self;
// Note: kSampleAdUnitId is a staticApId for example purposes. For personal Ads update kSampleAdUnitId with your interstitial ad unit id.
self.interstitial.adUnitID = kSampleAdUnitID;
[self.interstitial loadRequest:[self request]];
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.loadingSpinner.center = CGPointMake(CGRectGetWidth(self.view.bounds) / 2, self.loadingSpinner.center.y);
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial
{
isLoaded_ = YES;
}
- (void)interstitial:(GADInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error
{
isLoaded_ = NO;
}
//----ADS IMPLEMENTATION TILL HERE--->//
The timer "quickie_" here constantly checks if the Ad has successfully loaded and when it does, it shoots the Ad on the ViewController if the user still is on it. The static kSampleAdUnitID is a sampleId that always works. Thats it. Run your code and find your Interstitial Ad on your ViewController of choice.
Hope I helped. Cheers! :)

Edit and Delete Existing EKEvent?

I am using the Kal calendar in my app, (hopefully that doesn't change too much) but I get an EKEvent object from that depending on the user selection on the calendar.
Anyway, how can I edit and delete an event which already exists? Namely the EKEvent that I receive?
I need to do this all programatically, I am not using any of Apple's pre-made EKEventViewController's.
I can successfully create and save new events, but Im unsure of how to edit or delete existing ones, any help would be appreciated, thanks.
A complete answer would almost require a demo project.
Other approach would be simply giving you a link to Event Kit Programming Guide.
Since you did not provide any code (what you have tried already) i hope this extract from a working app will push you to the right track.
Note that i sublassed EKEventViewController due to app's specifics - this is not neccessary. I had to sublass it simply because original EKEventViewController
didn't spawn with black navigationBar (this was reported as a bug also, don't now if it's
fixed already).
You know how to add an event to calendar, so there's no need to write about getting a reference to EKEventStore and EKCalendar.
You're also not asking about how to retreive an event from calendar so let's assume you already have some kind of mechanism to select (receive) the event and you want to edit it. Let's say it is:
EKEvent *selectedEvent = (EKEvent *)[events objectAtIndex: selectedIndex];
I create this viewController as a property of appDelegate - you probably have better solution. appDelegate also holds eventStore and defaultCalendar reference - your approach could differ.
appDelegate.detailViewController = [[MPEventViewController alloc] initWithNibName:nil bundle:nil];
appDelegate.detailViewController.event = selectedEvent;
appDelegate.detailViewController.eventStore = appDelegate.eventStore;
appDelegate.detailViewController.defaultCalendar = appDelegate.defaultCalendar;
appDelegate.detailViewController.allowsEditing = NO;
[appDelegate.navigationController pushViewController:appDelegate.detailViewController animated:YES];
Sublcassing (again, this is not neccessary but it might come useful) goes like this:
MPEventEditViewController.h
#import <Foundation/Foundation.h>
#import <EventKitUI/EventKitUI.h>
#interface MPEventViewController : EKEventViewController <EKEventEditViewDelegate>
#property (nonatomic, strong) EKEventStore *eventStore;
#property (nonatomic, strong) EKCalendar *defaultCalendar;
- (void)editEvent:(id)sender;
#end
MPEventEditViewController.m
#import "MPEventViewController.h"
#import "----------AppDelegate.h"
#implementation MPEventViewController
#synthesize eventStore;
#synthesize defaultCalendar;
- (void)viewDidLoad {
[super viewDidLoad];
[self setTitle: [self.event title]];
self.allowsEditing = NO;
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemEdit target:self action:#selector(editEvent:)];
//this has nothing to do with the answer :)
//[[self.navigationController navigationBar] setTintColor: [UIColor colorWithHexString: NAVBAR_TINT_COLOR]];
}
- (void)editEvent:(id)sender {
EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];
//this has nothing to do with the answer :)
//[addController.navigationBar setTintColor: [UIColor colorWithHexString: NAVBAR_TINT_COLOR]];
addController.eventStore = self.eventStore;
addController.event = self.event;
addController.navigationBar.barStyle = UIBarStyleBlack;
addController.editViewDelegate = self;
[self presentModalViewController:addController animated:YES];
}
- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action {
NSError *error = nil;
EKEvent *thisEvent = controller.event;
switch (action) {
case EKEventEditViewActionCanceled:
break;
case EKEventEditViewActionSaved:
[controller.eventStore saveEvent:controller.event span: EKSpanFutureEvents error:&error];
break;
case EKEventEditViewActionDeleted:
[controller.eventStore removeEvent:thisEvent span: EKSpanFutureEvents error:&error];
break;
default:
break;
}
//here would be the place to reload data if you hold it in some kind of UITableView
[controller dismissModalViewControllerAnimated:YES];
}
- (EKCalendar *)eventEditViewControllerDefaultCalendarForNewEvents:(EKEventEditViewController *)controller {
EKCalendar *calendarForEdit = self.defaultCalendar;
return calendarForEdit;
}
- (void)dealloc {
eventStore = nil;
defaultCalendar = nil;
}
#end
Only after writing all this i remembered there is a great sample code SimpleEKDemo. In fact some of this posted code is probably originates from there.
EDIT:
After the question was edited the above answer became off-topic.
In that case you should take a look at EKCalendarItem and EKevent.
You can change allmost all properties programatically (most of them are inherited from EKCalendarItem).
Maybe you were distracted for example becaues hasNotes is readonly. That is because hasNotes is kind of a function and not a real property. Properties like notes, atendees, startDate, endDate etc. are perfectly editable.
For saving modified event you can still use:
NSError error = nil;
[self.eventStore saveEvent:event span: EKSpanFutureEvents error:&error];
And for deleting it:
NSError error = nil;
[self.eventStore removeEvent:event span: EKSpanFutureEvents error:&error];
EDIT2: for deleting all events try this:
//assuming self.eventStore is already properly set in code
//identifierArray would be your NSMutableArray holding event identifiers
//change the name according to your code
NSError error = nil;
for (NSString *eventIdentifier in removeAllObjects) {
EKEvent *event = [self.eventStore eventWithIdentifier:eventIdentifier];
[self.eventStore removeEvent:event span:EKSpanFutureEvents error:&error];
}
//now you can also clear identifiers
[removeAllObjects removeAllObjects];
Note: there's no guarantee you'll be able to delete all events - only events from
default calendar which is set by usert in settings app.

photo album on iphone

The below code is for go to photo albums.The below code shows an error. I'm adding the UIImagePickerControllerDelegates like this in my .h file:
#interface My_Pictures : UIViewController <UINavigationControllerDelegate,UIImagePickerControllerDelegates>
But I'm not importing anything in my .m file. Should I include any of the Frameworks? Please give me a clear explanation.
ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else {
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:ipc animated:YES];
You have to implement delegate like this in .h class
#interface My_Pictures : UIViewController<UIImagePickerControllerDelegate>
All the best.
UIImageWriteToSavedPhotosAlbum().

Programmatically control iPhone OS versions to enable functions for both OS 3.x and 4 - MFMessageComposeViewController problem

In order to support iPhone OS 3.x and 4.0 I programmatically control MFMessageComposeViewController functionality like this (use it only if the OS version is 4.0 or above):
// if iPhone OS version >= 4.0
if (os_version_num >= 4) {
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = text;
controller.recipients = [NSArray arrayWithObjects: nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
[controller release];
}
}
But, when I try to run it on iPhone 3.1.3 device, I immediately get the following error (even before application gets loaded):
dyld: Symbol not found: _OBJC_CLASS_$_MFMessageComposeViewController
Referenced from: /var/mobile/Applications/7232C474-FAD5-4E28-ABC5-8520F62300B0/TextMe.app/TextMe
Expected in: /System/Library/Frameworks/MessageUI.framework/MessageUI
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not safe to call dlopen at this time.)
What am I doing wrong?
You need to make sure you're doing a few things:
In your target's build settings:
set Base SDK to iPhone Device 4.0
set iPhone OS Deployment Target to iPhone OS 3.1.3 (or lower)
In your target's general settings, under Linked Libraries, change the "Type" next to MessageUI.framework to Weak.
Don't import <MessageUI/MFMessageComposeViewController.h> or it will crash on launch in 3.x. Just import <MessageUI/MessageUI.h>
I don't know what os_version_num is, but here's the code I use to test for the availability of MFMessageComposeViewController:
Class smsClass = (NSClassFromString(#"MFMessageComposeViewController"));
if (smsClass != nil && [MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = text;
controller.recipients = [NSArray arrayWithObjects: nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
[controller release];
}
Class theClass = NSClassFromString(#"MFMessageComposeViewController");
MFMessageComposeViewController *controller = theClass ? [[theClass alloc] init] : nil;
You can use the type MFMessageComposeViewController as in:
MFMessageComposeViewController *controller;
But you cannot use the global object MFMessageComposeViewController as in:
[MFMessageComposeViewController alloc];
Instead use the class lookup so you are not dependent on the linker:
[NSClassFromString(#"MFMessageComposeViewController") alloc];
In your target parameters, simply set messageUI.framework to type 'weak'
If you import <MessageUI/MessageUI.h> and set weak reference to MessageUI framework, you can directly call:
if ([MFMessageComposeViewController canSendText]) {
controller.body = body;
controller.recipients = [NSArray arrayWithObjects:number, nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
[controller release];
} else {
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:[NSString stringWithFormat:#"sms:%#",number]]];
}
On iOS 3.1.2 you will get nil in the if clause and old method will be launched.
I was having the same problem, and solved it a different way:
On the Left hand-side of your XCode window,
If you scroll down to the Bulls Eye with "Targets" and expand that
Expand your
< control > + < click > on "Link Binary With Libraries"
Choose "Add" --> "Existing Frameworks"
Choose "MessageUI.framework" and click on "Add"
That should add the Message UI to your app, tell me if it works.
What about if you have functions that you only want to include conditionally.
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
[self dismissModalViewControllerAnimated:YES];
}
For example, if the function definition contained MFMessageViewController, how do you make this part conditional (that is, not cause a problem with OS 3.x). Or is it not a problem at all?