change dismissVC to presentVC - ios

I am using following method two times for login and sign up. So some times I am getting crash. Here is my code:
- (void)signIn:(NSDictionary *)params {
[[PCUtilities sharedUtilities] showActivityControllerWithMessage:nil inController:self];
[[PCWebServiceManager sharedWebServiceManager] signInWithParameters:params completionHandler:^(id responseObject, NSError *error) {
self.signInBtn.enabled = YES;
// [[PCUtilities sharedUtilities] hideActivityIndicator];
if (error) {
[self forceLogout];
[PCUtilities showAlertWithTitle:nil message:error.localizedDescription cancelButtonTitle:#"OK"];
[[PCUtilities sharedUtilities] hideActivityIndicator];
}else {
PCLoginObject *loginObject = (PCLoginObject *)responseObject;
[self dismissViewControllerAnimated:NO completion:^{
[self performSelector:#selector(handleSignInResponse:) withObject:loginObject afterDelay:0.2];
}];
}
}];
}
In above code I am using this method as two time in two different classes, so if possible can any one help me to change the below line from dismissviewcontroller to presentViewcontroller
[self dismissViewControllerAnimated:NO
completion:^{
[self performSelector:#selector(handleSignInResponse:)
withObject:loginObject
afterDelay:0.2];
}];
I am using above method two times. So according to crash report I need to change any one method to present view controller. I have tried but no success.

Try adding this method ,this helped me in my case,when I got this warning
//pragma mark - Google SignIn Delegate
- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error {
}
// Present a view that prompts the user to sign in with Google
- (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController
{
[self presentViewController:viewController animated:YES completion:nil];
}
// Dismiss the "Sign in with Google" view
- (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
//completed sign In
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error {
//user signed in
//get user data in "user" (GIDGoogleUser object)
}

Try to set
[GIDSignIn sharedInstance].delegate = self;
in your viewDidAppear method,not in viewDidLoad

Related

Why is my Parse Sign Up Code Not Getting Ran?

In my main view controller, when a button is pressed I run the following code:
if (![PFUser currentUser]) { // No user logged in
// Create the log in view controller
CustomSignUp *logInViewController = [[CustomSignUp alloc] init];
[logInViewController setDelegate:self]; // Set ourselves as the delegate
// Create the sign up view controller
self.signUpViewController = [[TheActualSignUp alloc] init];
[self.signUpViewController setDelegate:self]; // Set ourselves as the delegate
self.signUpViewController.fields = (PFSignUpFieldsUsernameAndPassword
| PFSignUpFieldsSignUpButton
| PFSignUpFieldsEmail
| PFSignUpFieldsAdditional
| PFSignUpFieldsDismissButton);
[self.signUpViewController.signUpView.additionalField setPlaceholder:#"First & Last Name"];
[logInViewController setSignUpController:self.signUpViewController];
logInViewController.facebookPermissions = #[ #"email", #"public_profile", #"user_friends" ];
logInViewController.fields = (PFLogInFieldsUsernameAndPassword
| PFLogInFieldsFacebook
| PFLogInFieldsTwitter
| PFLogInFieldsLogInButton
| PFLogInFieldsSignUpButton
| PFLogInFieldsPasswordForgotten);
// Present the log in view controller
[self.navigationController pushViewController:logInViewController animated:YES];
}
The view controller for a login screen shows up, and I can successfully log in an already created user. However, when I try to sign up someone, I run into issues. The sign up window appears fine, and I type in all the codes, but when I click the button to send the info in to sign it up, nothing happens. Here is the code (in the same view controller). Would greatly appreciate any help on this. Am using Parse on Buddy.com. None of the NSLogs are getting called when signing up.
- (BOOL)logInViewController:(PFLogInViewController *)logInController shouldBeginLogInWithUsername:(NSString *)username password:(NSString *)password {
// Check if both fields are completed
if (username && password && username.length != 0 && password.length != 0) {
return YES; // Begin login process
}
[[[UIAlertView alloc] initWithTitle:#"Missing Information"
message:#"Make sure you fill out all of the information!"
delegate:nil
cancelButtonTitle:#"ok"
otherButtonTitles:nil] show];
return NO; // Interrupt login process
}
// Sent to the delegate when a PFUser is logged in.
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
PFUser *me = [PFUser currentUser];
NSLog(#"Regular Login");
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)logInViewController:(PFLogInViewController *)logInController didFailToLogInWithError:(NSError *)error {
NSLog(#"Failed to log in...%#", error);
}
// Sent to the delegate when the log in screen is dismissed.
- (void)logInViewControllerDidCancelLogIn:(PFLogInViewController *)logInController {
[self.navigationController popViewControllerAnimated:YES];
}
- (BOOL)signUpViewController:(PFSignUpViewController *)signUpController shouldBeginSignUp:(NSDictionary *)info {
NSLog(#"Signup");
BOOL informationComplete = YES;
// loop through all of the submitted data
for (id key in info) {
NSString *field = [info objectForKey:key];
if (!field || field.length == 0 || ![signUpController.signUpView.additionalField.text containsString:#" "] ) { // check completion
informationComplete = NO;
break;
}
}
// Display an alert if a field wasn't completed
if (!informationComplete) {
[[[UIAlertView alloc] initWithTitle:#"Missing Information"
message:#"Make sure you fill out all of the information, including first & last name!"
delegate:nil
cancelButtonTitle:#"ok"
otherButtonTitles:nil] show];
}
return informationComplete;
}
- (void)signUpViewController:(PFSignUpViewController *)signUpController didSignUpUser:(PFUser *)user {
NSLog(#"Signed them up");
[user saveEventually];
[self dismissViewControllerAnimated:YES completion:nil]; // Dismiss the PFSignUpViewController
}
// Sent to the delegate when the sign up attempt fails.
- (void)signUpViewController:(PFSignUpViewController *)signUpController didFailToSignUpWithError:(NSError *)error {
NSLog(#"Failed to sign up...");
}
// Sent to the delegate when the sign up screen is dismissed.
- (void)signUpViewControllerDidCancelSignUp:(PFSignUpViewController *)signUpController {
NSLog(#"User dismissed the signUpViewController");
}
Looking through your code, it's not immediately obvious as to what the problem is. If you ping Parse on Buddy's customer support at support#buddy.com, we can help.

-(void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error -- Method is not call

I want to get fetch user's all information who logged in with Google+ in my app.
-(void)googleSignInButtonMethod{
[[UIApplication sharedApplication] delegate];
signIn = [GPPSignIn sharedInstance];
signIn.clientID = kClientId;
[signIn authenticate];
signIn.shouldFetchGoogleUserID=YES;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.scopes = #[ kGTLAuthScopePlusLogin ];
signIn.delegate = self;
[signIn authenticate];
}
after that,
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
NSLog(#"Received Error %# and auth object==%#",error,auth);
if(!error) {
NSLog(#"%#", signIn.authentication.userEmail);
}
}
I followed all the instruction provided by google+ developers site. I set all the delegates and import all important files.
In .h file
#property (weak, nonatomic) IBOutlet GIDSignInButton *gmailSignInButton;
-(IBAction)gmailBtn:(GIDSignIn *)sender;
In .m file
- (IBAction)gmailBtn:(GIDSignIn *)sender {
[[AFNetworkReachabilityManager sharedManager]startMonitoring];
//Checking the Internet connection...
[[AFNetworkReachabilityManager sharedManager]setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status){
if (status == AFNetworkReachabilityStatusReachableViaWWAN || status == AFNetworkReachabilityStatusReachableViaWiFi) {
[GIDSignIn sharedInstance].uiDelegate = self;
[[GIDSignIn sharedInstance] signIn];
}else{
NSLog(#"No Network");
}
}];
}
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error {
// Perform any operations on signed in user here.
NSLog(#"user ID: %#",user.userID);
NSLog(#"user Token: %#",user.authentication.idToken);
NSLog(#"user name: %#",user.profile.name);
NSLog(#"user givenName: %#",user.profile.givenName);
NSLog(#"user family Name: %#",user.profile.familyName);
NSLog(#"user email: %#",user.profile.email);
NSURL *profileURL;
if (user.profile.hasImage)
{
profileURL = [user.profile imageURLWithDimension:100];
}
NSMutableDictionary *userData = [NSMutableDictionary dictionary];
[userData setValue:user.userID forKey:#"id"];
[userData setValue:user.profile.givenName forKey:#"first_name"];
[userData setValue:user.profile.familyName forKey:#"last_name"];
[userData setValue:#"" forKey:#"gender"];
[userData setValue:user.profile.email forKey:#"email"];
[userData setValue:profileURL forKey:#"profileImg"];
}
- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error{
// [self presentViewController:viewController animated:YES completion:nil];
}
- (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController {
[self presentViewController:viewController animated:YES completion:nil];
}
// Dismiss the "Sign in with Google" view
- (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
*don't forget to declare gmail delegate GIDSignInUIDelegate,GIDSignInDelegate

Calling API for GoogleMap objective c

Can anyone guide me how we can use place auto complete in GoogleMap after all the steps completed for installing pod for GoogleMaps into the project?? I have no idea about this please somebody help me!!!
I hope u have integrated google pods successfully
Import google map class
#import GoogleMaps;
Add delegate
<GMSAutocompleteViewControllerDelegate>
I have button in my screen to go for autocomplete screen.
On button IBAction write this code
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
and implement GMSAutocompleteViewControllerDelegate
- (void)viewController:(GMSAutocompleteViewController *)viewControllerdidAutocompleteWithPlace:(GMSPlace *)place {
[self dismissViewControllerAnimated:YES completion:nil];
// Do something with the selected place.
NSLog(#"Place name %#", place.name);
NSLog(#"Place address %#", place.formattedAddress);
NSLog(#"Place attributions %#", place.attributions.string);
}
- (void)viewController:(GMSAutocompleteViewController *)viewControllerdidFailAutocompleteWithError:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:nil];
// TODO: handle the error.
NSLog(#"Error: %#", [error description]);
}
// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController*)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController*)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

MFMessageComposeViewController not returning to application after send message ios9

Previously on iOS7, I have tested my SMS module and it worked nicely. After updating the iOS version, I noticed that the SMS module have some problems.
In my .h file
#import <MessageUI/MFMessageComposeViewController.h>
#interface ViewController : UIViewController<UITextFieldDelegate,MFMessageComposeViewControllerDelegate>
In my .m file
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
if (result == MessageComposeResultCancelled){
NSLog(#"Message cancelled");
}
else if (result == MessageComposeResultSent){
NSLog(#"Message sent");
}
else{
NSLog(#"Message failed");
}
}
After I press send, in the log have show "Message sent" but the view is still at the message screen. I have no idea why it will not go back to my application.
Need help to find the problem to why it will not go back to my application.
Thanks in advance.
It seems you are not dismissing the mailcomposer after it is presented. You will have to dismiss the presented MFMessageComposeViewController in the following method:
-(void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
if (result == MessageComposeResultCancelled){
NSLog(#"Message cancelled");
}
else if (result == MessageComposeResultSent){
NSLog(#"Message sent");
}
else{
NSLog(#"Message failed");
}
[self dismissViewControllerAnimated:YES completion:nil]; //<---- This line
}
Moreover, - (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated is deprecated since iOS 6. Use - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion instead like this:
[self presentViewController:mailComposer animated:YES completion:nil];

App runs on iPhone 5s but not on iPhone 4s

I am using Xcode 6 beta with iOS 8 on the iPhone 5s the iphone 4s is standard ios 7.1 phone.
The app runs great on the iPhone 5s but as soon as a try a iphone 4s or the iPhone 4s simulator.
the app breaks out and throws the following error
dyld: Symbol not found: _NSURLAuthenticationMethodClientCertificate
Referenced from: /Users/MIkeAspinall 1/Library/Developer/CoreSimulator/Devices/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/data/Applications/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/WeddingsAndMore.app/WeddingsAndMore
Expected in: /Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/Frameworks/CFNetwork.framework/CFNetwork
in /Users/MIkeAspinall 1/Library/Developer/CoreSimulator/Devices/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/data/Applications/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/WeddingsAndMore.app/WeddingsAndMore
(lldb)
I'm not sure why this is happening. But the iPhone 5s simulator throws the same error. It just seems to run on the iOS 8.
the settings are set for an ios 7.1 phone
im also using parse.com for my data access
My Phone is Iphone 5s Running ios 8 beta
iphone 4s is running ios 7.1
simulators are running in xcode 6beta
app is set to run on ios 7.1 or above.
i'm using xcode 6beta
hope that clears up what i have
opening code on first view controler
#interface DMKHomeViewController (UIViewcontroller )
#end
#implementation DMKHomeViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(BOOL) hasInternet{
Reachability *reach = [Reachability reachabilityWithHostName:#"www.bbc.co.uk"];
NetworkStatus internetStats = [reach currentReachabilityStatus];
if (internetStats == NotReachable) {
UIAlertView *alertOne = [[UIAlertView alloc] initWithTitle:#"No Internet Connection" message:#" A connection To The Internet IS Required While Running This App. Please Reconnect To Continue" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:#"Cancel", nil];
[alertOne show];
}
else {
UIAlertView *alerttwo = [[UIAlertView alloc] initWithTitle:#"Internet Connection Active" message:#"A connection To The Internet IS Required While Running This App. Your Connection Is Live... Thankyou." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Cancel", nil];
[alerttwo show];
}
return YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self hasInternet];
if (![PFUser currentUser]) { // No user logged in
// Create the log in view controller
PFLogInViewController *logInViewController = [[PFLogInViewController alloc] init];
[logInViewController setDelegate:self]; // Set ourselves as the delegate
// Create the sign up view controller
PFSignUpViewController *signUpViewController = [[PFSignUpViewController alloc] init];
[signUpViewController setDelegate:self]; // Set ourselves as the delegate
// Assign our sign up controller to be displayed from the login controller
[logInViewController setSignUpController:signUpViewController];
// Present the log in view controller
[self presentViewController:logInViewController animated:YES completion:NULL];
}
}
// Sent to the delegate to determine whether the log in request should be submitted to the server.
- (BOOL)logInViewController:(PFLogInViewController *)logInController shouldBeginLogInWithUsername: (NSString *)username password:(NSString *)password {
// Check if both fields are completed
if (username && password && username.length != 0 && password.length != 0) {
return YES; // Begin login process
}
[[[UIAlertView alloc] initWithTitle:#"Missing Information"
message:#"Make sure you fill out all of the information!"
delegate:nil
cancelButtonTitle:#"ok"
otherButtonTitles:nil] show];
return NO; // Interrupt login process
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.canDisplayBannerAds = YES;
}
// Sent to the delegate to determine whether the sign up request should be submitted to the server.
- (BOOL)signUpViewController:(PFSignUpViewController *)signUpController shouldBeginSignUp:(NSDictionary *)info {
BOOL informationComplete = YES;
// loop through all of the submitted data
for (id key in info) {
NSString *field = [info objectForKey:key];
if (!field || field.length == 0) { // check completion
informationComplete = NO;
break;
}
}
// Display an alert if a field wasn't completed
if (!informationComplete) {
[[[UIAlertView alloc] initWithTitle:#"Missing Information"
message:#"Make sure you fill out all of the information!"
delegate:nil
cancelButtonTitle:#"ok"
otherButtonTitles:nil] show];
}
return informationComplete;
}
// Sent to the delegate when a PFUser is signed up.
- (void)signUpViewController:(PFSignUpViewController *)signUpController didSignUpUser:(PFUser *)user {
[self dismissViewControllerAnimated:YES completion:NULL]; // Dismiss the PFSignUpViewController
}
// Sent to the delegate when the sign up attempt fails.
- (void)signUpViewController:(PFSignUpViewController *)signUpController didFailToSignUpWithError: (NSError *)error {
NSLog(#"Failed to sign up...");
}
// Sent to the delegate when the sign up screen is dismissed.
- (void)signUpViewControllerDidCancelSignUp:(PFSignUpViewController *)signUpController {
NSLog(#"User dismissed the signUpViewController");
}
// Sent to the delegate when a PFUser is logged in.
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
[self dismissViewControllerAnimated:YES completion:NULL];
}
// Sent to the delegate when the log in attempt fails.
- (void)logInViewController:(PFLogInViewController *)logInController didFailToLogInWithError: (NSError *)error {
NSLog(#"Failed to log in...");
}
// Sent to the delegate when the log in screen is dismissed.
- (void)logInViewControllerDidCancelLogIn:(PFLogInViewController *)logInController {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
DMKHomeViewController *destination = [segue destinationViewController];
destination.interstitialPresentationPolicy = ADInterstitialPresentationPolicyAutomatic;
}
- (IBAction)Logout:(id)sender {
[PFUser logOut];
// Present the log in view controller
if (![PFUser currentUser]) { // No user logged in
// Create the log in view controller
PFLogInViewController *logInViewController = [[PFLogInViewController alloc] init];
[logInViewController setDelegate:self]; // Set ourselves as the delegate
// Create the sign up view controller
PFSignUpViewController *signUpViewController = [[PFSignUpViewController alloc] init];
[signUpViewController setDelegate:self]; // Set ourselves as the delegate
// Assign our sign up controller to be displayed from the login controller
[logInViewController setSignUpController:signUpViewController];
// Present the log in view controller
[self presentViewController:logInViewController animated:YES completion:NULL];
}
}

Resources