- (IBAction)button_number1:(id)sender {
MFMessageComposeViewController *textComposer = [[MFMessageComposeViewController alloc] init];
[textComposer setMessageComposeDelegate:self];
if ([MFMessageComposeViewController canSendText]) {
[textComposer setRecipients:#[string_numberphone]];
[textComposer setBody:#"ABC"];
[self presentViewController:textComposer animated:YES completion:NULL];
} else {
NSLog(#"Can't Open Text");
}
}
}
when I click a button_number1, it does not work, and no arlet Error.
But when clicking the button below, it works normally on iOS 7 but I can not assign the message content.
Please guide me how to assign the message content to this button_number2.
- (IBAction)button_number2:(id)sender {
NSString *message = [[NSString alloc] initWithFormat:#"sms:%#",string_numberphone];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:message ]];
}
Thank so much!
in .h header file.....
#import <MessageUI/MessageUI.h>
#interface MainViewController : UIViewController <MFMessageComposeViewControllerDelegate>{
- (IBAction)sendsms:(id)sender;
}
in .m implementation file.....
- (IBAction)showEmail:(id)sender{
if (phoneNumber!=NULL) {
UIDevice *device = [UIDevice currentDevice];
if ([[device model] isEqualToString:#"iPhone"] ) {
NSString *phNo = [phoneNumber stringByReplacingOccurrencesOfString:#" " withString:#""];
NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt:%#",phNo]];
if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {
[[UIApplication sharedApplication] openURL:phoneUrl];
} else
{
UIAlertView *calert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Call facility is not available!!!" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil, nil];
[calert show];
[calert release];
}
} else {
UIAlertView *warning =[[UIAlertView alloc] initWithTitle:#"Alert" message:#"Your device doesn't support this feature." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warning show];
[warning release];
}
}
else {
UIAlertView *warning =[[UIAlertView alloc] initWithTitle:#"Alert" message:#"Phone No is not Available." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warning show];
[warning release];
}
}
Related
I'm trying to check if the current user has verified it's email before
they proceed to the next step. What am i doing wrong please help thank you. The phone number saving in background works.. When i call on the "SavePhoneInBackground" the app crashes
(The SVProgressHUd is the activity indicator)
-(void) SavePhoneInBackground {
PFUser *user = [PFUser currentUser];
user[#"phone"] = _phone_register.text;
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
NSLog(#"PhoneUpdatingSucces!");
_phone_register.text = nil;
[self checkUserEmailVerify];
}else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Whoops!" message:#"Something went wrong! Try again." delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil];
[alert show];
[SVProgressHUD dismiss];
NSLog(#"There was an error in the registration!");
}
}];
}
-(void) checkUserEmailVerify {
PFUser *user = [PFUser currentUser];
if (![[user objectForKey:#"emailVerified"] boolValue]) {
// Refresh to make sure the user did not recently verify
[user refresh];
if (![[user objectForKey:#"emailVerified"] boolValue]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Whoops!" message:#"You need to verify your emailadress!" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
return;
[SVProgressHUD dismiss];
}
}
// This is a triumph.
[SVProgressHUD dismiss];
[self performSegueWithIdentifier:#"login2" sender:self];
}
func giveCaketoUser(user: PFUser) {
if (user.objectForKey("emailVerified").boolValue == true){
println("true")
} else {
println("flase")
}
}
Here is something I used in one of my recent projects:
- (BOOL)validateEmail:(NSString *)emailStr {
NSString *emailRegex = #"[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", emailRegex];
return [emailTest evaluateWithObject:emailStr];
}
There are other manipulations of the regex you can use. When I used this method the problem I had was that the project would continue to register the user while still showing my custom alert and NSLog error, but that may have been failure on my end and not the method.
Hope this will send you down the right direction!
This is how I did it in my App and it will only let verified email users to access. You will need to modify it slightly for what you want.
- (void)logInViewController:(MyLogInViewController *)logInController didLogInUser:(PFUser *)user {
if (![[user objectForKey:#"emailVerified"] boolValue]){
NSLog(#"User not validated email");
[[[UIAlertView alloc] initWithTitle:#"Access restricted" message:#"To access this area please validate your email address" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
}
else if ([[user objectForKey:#"emailVerified"] boolValue]){
NSLog(#"Email validated");
[self dismissViewControllerAnimated:YES completion:NULL];
[[[UIAlertView alloc] initWithTitle:#"Welcome back" message:(#"%#", user.username) delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
}
// [self dismissViewControllerAnimated:YES completion:NULL];
NSLog(#"Login sucessfull and username is %#",user.username);
}
Hope this helps if you have not worked it out yet!
I am creating a student index app, in which you can save names, pictures and roles of students. Everything works just fine, but my code does not save images in my Core Data Model. I have been trying to figure it out the whole day.
You can find my whole project here: http://www21.zippyshare.com/v/26184330/file.html
#import "AddStudent.h"
#import "Studenten.h"
#import "Bild.h"
#import <QuartzCore/QuartzCore.h>
#interface AddStudent () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#end
#implementation AddStudent;
#synthesize delegate;
#synthesize managedObjectContext = _managedObjectContext;
#synthesize selectedBetreuungsgrund;
#synthesize studentBetrGrundCell = _studentBetrGrundCell;
#synthesize vorschauImageView = _vorschauImageView;
- (void)viewWillAppear:(BOOL)animated {
_studentBetrGrundCell.textLabel.text = #"";
_studentBetrGrundCell.delegate = self;
_studentBetrGrundCell.managedObjectContext = self.managedObjectContext;
}
- (void)betrGrundWasSelectedOnPicker:(Betreuungsgrund *)betreuungsgrund {
self.selectedBetreuungsgrund = betreuungsgrund;
_studentBetrGrundCell.textLabel.text = self.selectedBetreuungsgrund.name;
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (void)dismissKeyboard {
[self.view endEditing:TRUE];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.studentNachnameTextfeld.delegate = self;
self.studentVornameTextFeld.delegate = self;
_studentNachnameTextfeld.autocapitalizationType = UITextAutocapitalizationTypeSentences;
_studentVornameTextFeld.autocapitalizationType = UITextAutocapitalizationTypeSentences;
UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(dismissKeyboard)];
[tgr setCancelsTouchesInView:NO];
[self.tableView addGestureRecognizer:tgr];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
- (IBAction)save:(id)sender
{
if (([_studentNachnameTextfeld.text isEqualToString:(#"")])||([_studentVornameTextFeld.text isEqualToString:(#"")])){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:#"Sie müssen alle Namensfelder ausfüllen!" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[alert show];
}
else {
Student *student = [NSEntityDescription insertNewObjectForEntityForName:#"Student"
inManagedObjectContext:self.managedObjectContext];
student.vorname = _studentVornameTextFeld.text;
student.name = _studentNachnameTextfeld.text;
student.hatBetrGrund = selectedBetreuungsgrund; //Funzt trotzdem
student.bild.vorschauData = _vorschauImageView.image;
NSLog(#"Image Core Data: %#", _vorschauImageView.image);
NSLog(#"Image Core Data DB: %#", student.bild.vorschauData);
// NSLog(#"Betreuungsgrund: %#", student.hatBetrGrund);
[self.managedObjectContext save:nil]; // Eintrag in Datenbank
[self.delegate AddStudentSavePressed:self];
NSLog (#"Save Button bei AddBetrGrund pressed");
}
}
- (IBAction)albumButtonPressed:(id)sender
{
if (! [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] ) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Error" message:#"Es steht kein Album zur Verfügung!" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[alert show];
return;
}
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.delegate = self;
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:controller animated:YES completion:nil];
}
- (IBAction)kameraButtonPressed:(id)sender
{
if (! [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Error" message:#"Es steht keine Kamera zur Verfügung!" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[alert show];
return;
}
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.delegate = self;
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:controller animated:YES completion:nil];
}
- (IBAction)deleteBildPressed:(id)sender {
self.vorschauImageView.image = nil;
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissViewControllerAnimated:YES completion:nil];
_vorschauImageView.image = image;
_vorschauImageView.layer.cornerRadius = 10; // abgerundete Ecken
NSLog(#"Image Vorschau: %#", _vorschauImageView.image);
}
Thanks in advance for ur help. Cheers
Generally you shouldn't save the image in Core Data. Instead, save it in a file on disk and save the path to the file in Core Data model.
This line:
student.bild.vorschauData = _vorschauImageView.image;
makes it look like the student has a relationship (bild) to some other object which contains the image. You need to create that object, insert it into the context and associated it with the student before you can use it.
how can i update image in sqlite
I have an image from imagePickerView and i want to save it in blob format in my sql how can that posibale my sorce code hear
NSString *item = str_Name;
sqlite3_stmt *statement;
NSString *databasePath = [[NSBundle mainBundle] pathForResource:#"SLAMEBOOK" ofType:#"sql"];
if(sqlite3_open([databasePath UTF8String], &SLAMEBOOK) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat: #"UPDATE SlammyDetail SET Name= \"%#\", BDate=\"%#\" WHERE Name = \"%#\"", txt_Name.text ,lbl_date.text, item];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(SLAMEBOOK, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"REMINDER Updated"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Failed to add Task"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
sqlite3_finalize(statement);
sqlite3_close(SLAMEBOOK);
}
[txt_Name resignFirstResponder];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
I have implemented correctly bump's api, and added this code:
- (void) configureBump {
[BumpClient configureWithAPIKey:#"your api key" andUserID:[[UIDevice currentDevice] name]];
[[BumpClient sharedClient] setMatchBlock:^(BumpChannelID channel) {
/* UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Matched with user" message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil ];
[alert show];
[alert release];*/
NSLog(#"Matched with user: %#", [[BumpClient sharedClient] userIDForChannel:channel]);
[[BumpClient sharedClient] confirmMatch:YES onChannel:channel];
}];
[[BumpClient sharedClient] setChannelConfirmedBlock:^(BumpChannelID channel) {
/* UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Channel with" message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil ];
[alert show];
[alert release];*/
NSLog(#"Channel with %# confirmed.", [[BumpClient sharedClient] userIDForChannel:channel]);
[[BumpClient sharedClient] sendData:[[NSString stringWithFormat:#"hi"] dataUsingEncoding:NSUTF8StringEncoding]
toChannel:channel];
}];
[[BumpClient sharedClient] setDataReceivedBlock:^(BumpChannelID channel, NSData *data) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Data received" message:[NSString stringWithCString:[data bytes] encoding:NSUTF8StringEncoding] delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil ];
[alert show];
[alert release];
NSLog(#"Data received from %#: %#",
[[BumpClient sharedClient] userIDForChannel:channel],
[NSString stringWithCString:[data bytes] encoding:NSUTF8StringEncoding]);
NSString *receivedBumpData=[NSString stringWithCString:[data bytes] encoding:NSUTF8StringEncoding];
if(receivedBumpData.length!=0){
CardAvailableLandscape *cardObject=[[CardAvailableLandscape alloc] init];
[cardObject bumpInsertFunction:receivedBumpData];
}
}];
[[BumpClient sharedClient] setConnectionStateChangedBlock:^(BOOL connected) {
if (connected) {
/* UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"bump Coneected" message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil ];
[alert show];
[alert release];*/
NSLog(#"Bump connected...");
} else {
/* UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Bump disconnected..." message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil ];
[alert show];
[alert release];*/
NSLog(#"Bump disconnected...");
}
}];
[[BumpClient sharedClient] setBumpEventBlock:^(bump_event event) {
switch(event) {
case BUMP_EVENT_BUMP:{
/*UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Bump detected." message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil ];
[alert show];
[alert release];*/
NSLog(#"Bump detected.");
break;
}
case BUMP_EVENT_NO_MATCH:
{
/*UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"No match." message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil ];
[alert show];
[alert release];*/
NSLog(#"No match.");
break;
}
}
}];
}
this code has been taken from the example project. the connection is established. but i can't seem to be able to send a file: I tried this tutorial:
http://appgenor.blogspot.it/2010/02/using-bumps-new-api-to-exchange-data.html
but the Bumb object can not be created. it gives me an error. the bump has not been implemented. so it is not in the sdk, i think...
bumpObject = [[Bump alloc] init]; // Bump *bumpObject;
help please!!
I looked at the link you mention and it seems a bit old. You create bump object using static function: [BumpClient sharedClient], which also calls connect for you. I am trying to play with it as well but having problems where bump is detected but I can send data. I am using an iPod and bu.mp website to test the code.
Im creating a view in Xcode 4.3 and im unsure how to specify multiple UIAlertView's that have their own buttons with separate actions. Currently, my alerts have their own buttons, but the same actions. Below is my code.
-(IBAction)altdev {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"titleGoesHere"
message:#"messageGoesHere"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Continue", nil];
[alert show];
}
-(IBAction)donate {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"titleGoesHere"
message:#"messageGoesHere"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Continue", nil];
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.examplesite1.com"]];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"examplesite2.com"]];
}
}
Thanks for any help!
There is a useful property tag for UIView(which UIAlertView subclass from). You can set different tag for each alert view.
UPDATE:
#define TAG_DEV 1
#define TAG_DONATE 2
- (IBAction)altdev {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"titleGoesHere"
message:#"messageGoesHere"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Continue", nil];
alert.tag = TAG_DEV;
[alert show];
}
- (IBAction)donate {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"titleGoesHere"
message:#"messageGoesHere"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Continue", nil];
alert.tag = TAG_DONATE;
[alert show];
}
-(void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == TAG_DEV) { // handle the altdev
...
} else if (alertView.tag == TAG_DONATE){ // handle the donate
}
}
easier & newer
UIAlertView *alert = [[UIAlertView alloc] init...
alert.tag = 1;
UIAlertView *alert = [[UIAlertView alloc] init...
alert.tag = 2;
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(alertView.tag == 1) {
// first alert...
} else {
// sec alert...
}
}
all done!
If you find it dificult to use delegate methods to differently identifying alert view Then you can also use This Category class to use completion Block for each AlertView.
Alert_ActionSheetWithBlocks
For eg.
UIAlertView* alert1 = [[UIAlertView alloc] initWithTitle:#"AlertView+Block 1" message:#"WithBlocks" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[alert1 showWithFinishBlock:^(UIAlertView *alertView, NSInteger buttonIndex){ //--AlertView1 Stuff here }];
UIAlertView* alert2 = [[UIAlertView alloc] initWithTitle:#"AlertView+Block 2" message:#"WithBlocks" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[alert2 showWithFinishBlock:^(UIAlertView *alertView, NSInteger buttonIndex){ //--AlertView2 Stuff here }];
I hope this one is the more easiest way as compare to tag + delegate method..
He's right but you need to add this:
-(void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == TAG_DEV && buttonIndex == 1) { // handle the altdev
...
} else if (alertView.tag == TAG_DONATE && buttonIndex == 1){ // handle the donate
}
}
if buttonIndex==1 then you're using the FIRST otherbutton. 0 would be for cancel. But just do nothing for 0
Or you could do this (check the title name), is just another option... Mind identically titled alerts though!
-(IBAction)altdev {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"titleOneGoesHere"
message:#"messageGoesHere"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Continue", nil];
[alert show];
}
-(IBAction)donate {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"titleTwoGoesHere"
message:#"messageGoesHere"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Continue", nil];
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1)
{
if([[alertView title] isEqualToString:#"titleOneGoesHere"])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.examplesite1.com"]];
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"examplesite2.com"]];
}
}