Missing sentinel in UIAlertView allocation - objective-c

UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Error"
message:#"Some failure message"
delegate:self
cancelButtonTitle:#"cancel"
otherButtonTitles:#"retry", nil
];
[alert show];
[alert release];
I got two warnings pointing at this block of code.
Unused variable 'alert'
Missing sentinel in function call
My code looks similar to all the examples online. Why is it broken?

This code works fine for me. Try cleaning all targets and building again to see if the error persists.
Because you call [alert show], you should not get an unused variable warning on alert.
Since you include nil after otherButtonTitles, you should not get a missing sentinel warning.

Related

Objective-C Firebase reloadWithCompletion not executing completion code

My code is not executing the completion callback after calling reloadWithCompletion
if ([FIRAuth auth].currentUser.isEmailVerified) {
_emailField.text = [FIRAuth auth].currentUser.email;
} else {
[[FIRAuth auth].currentUser reloadWithCompletion:^(NSError * _Nullable error) {
if ([FIRAuth auth].currentUser.isEmailVerified) {
_emailField.text = [FIRAuth auth].currentUser.email;
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Email Validation"
message:#"Your email must be validated to continue."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}];
}
Any help is appreciated.
As it turns out I fixed the problem but I still don't know why or how the completion code was not working for this user. I simply used the Firebase Authentication console to delete the user record. My app then re-created the record and now the completion code executes properly.

Xcode: Multiple text lines in pop-up

I'm trying to create a text box with multiple fields, but I'm having trouble getting the second to show (as a matter of fact, when I type the second field in, it causes my text box not to show up all together.)
Here's what I have:
-(IBAction)popupCheckIn {
//UIAlertView *alertCheckIn = [[UIAlertView alloc] initWithTitle:#"Check in" message:#"Please fill out the following to check in." delegate:self cancelButtonTitle:#"Check in." otherButtonTitles:#"Cancel.", nil];
//[alertCheckIn show];
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"Check in" message:#"Please fill out the following fields to check in." delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * nameField = [alert textFieldAtIndex:0];
nameField.keyboardType = UIKeyboardTypeDefault;
nameField.placeholder = #"Your Name";
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * hostField = [alert textFieldAtIndex:1];
hostField.keyboardType = UIKeyboardTypeDefault;
hostField.placeholder = #"Host Name";
[alert addButtonWithTitle:#"Check in."];
[alert show];
When I run this code, I get an error that says "Thread 1: signal SIGABRT" and my pop up won't come up at all; when I have just the name field, it works fine.
What am I doing wrong with my second text field? Thanks!
I think that your error arises because that type of UIAlertView doesn't contain more than one UITextField, and when trying to access the second it raises a NSRangeException. This is according to the docs.
https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html#//apple_ref/occ/instm/UIAlertView/textFieldAtIndex:
I tried your code, the entire error message is:
2014-06-26 17:13:56.213 Testing1[2444:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'textFieldIndex (1) is outside of the bounds of the array of text fields'
The issue, is that you only have ONE UITextField with the UIAlertViewStyle set to UIAlertViewStylePlainTextInput. So this part of code ([alert textFieldAtIndex:1] is causing the crash).
Repeating the line alert.alertViewStyle = UIAlertViewStylePlainTextInput; won't create a new one.
The only way to get 2 UITextFields, is to use the UIAlertViewStyleLoginAndPasswordInput UIAlertViewStyle.
A way could be then to set the second one (like the first one) is like this:
[hostField setSecureTextEntry:FALSE];
But personally, I think that I don't recommend it. It may be blocked in the future.
Since we cannot custom really the existing UIAlertView since iOS7 (can't add subview), I'd suggest you create (or find in CocoaControls/GitHub) your own CustomAlertView-like.
You'll want to use alert with the alert style UIAlertViewStyleLoginAndPasswordInput. See this answer: UIAlertView with Two TextFields and Two Buttons

IBAction makes errors on theos compiling

I'm new to Objective-C programming and I want to make a simple tweak about VLC for iOS.app but I can't compile.
Here's my code :
#import <UIKit/UIKit.h>
%hook VLCMovieViewController
-(IBAction)playPause
{
if([_mediaPlayer isPlaying]) {
UIAlertView *pause = [[UIAlertView alloc] initWithTitle:#"PAUSED" message:#"Your movie is paused" delegate:nil cancelButtonTitle:nil otherButtonTitles:#"OK !", nil];
[_listPlayer pause];
[pause show];
[pause release];
}
else
{
UIAlertView *play = [[UIAlertView alloc] initWithTitle:#"PLAYING" message:#"Your movie is playing" delegate:nil cancelButtonTitle:nil otherButtonTitles:#"OK !", nil];
[_listPlayer play];
[play show];
[play release];
}
}
%end
I don't find any mistakes in my codes but when I try to compile, theos returns me an error :
Preprocessing Tweak.xm...
Compiling Tweak.xm...
Tweak.xm:6:8: error: expected unqualified-id
static IBAction (*_logos_orig$_ungrouped$VLCMovieViewController$playPause)(VLCMovieViewController*, SEL); s...
^
<built-in :24:22: note: expanded from here
#define IBAction void)__attribute__((ibaction)
^
1 error generated.
make[2]: *** [obj/Tweak.xm.708dff35.o] Error 1
make[1]: *** [internal-library-all_] Error 2
make: *** [VLCTweak.all.tweak.variables] Error 2
Have you any clue to make it working ?
Many thanks in advance
You don't need to use IBAction with Theos, as you don't use Interface Builder.
IBAction is only a way to tell Xcode and Interface Builder to link UI elements to your code.
Replacing -(IBAction)playPause by -(void)playPause should work

json ObjectForKey New Line

Problem: The UIAlertView show \ninstead break a line, from a Json response.
Json Response:
{"error":"Line 1.\\nLine 2."}
Code
[self setLastError:[dictJsonResult jsonObjectForKey:#"error"]];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Registration Failed"
message:[ParseHelper lastError] delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] autorelease];
So Ismael already explained what's wrong; I tell you how to fix it:
[self setLastError:[[dictJsonResult jsonObjectForKey:#"error"]
stringByReplacingOccurrencesOfString:#"\\n" withString:#"\n"]];
The problem is that \\ translates to \ and it takes precedence because it comes first.
To explain a little further
ABC\\nDEF looks like:
ABC\nDEF
ABC\nDEF looks like:
ABC
DEF

iOS: My Alert message is displayed twice, but the code is only executed once

Here is my code that calls "displayAlert". The problem is not only do I get an error message (wait_fences: failed to receive reply: 10004003) but the "alert" is displayed twice!
if(gSiteID.globalSiteID.length == 0) { // user didn't choose site
[self displayAlert:NSLocalizedString(#"Missing Site ID", nil) andData:NSLocalizedString(#"You must choose a site from the View Sites page",nil)];
return;
}
This the code for "displayAlert":
- (void) displayAlert: (NSString *) title andData: (NSString *) errorMsg {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: title
message: errorMsg
delegate:nil
cancelButtonTitle: #"OK"
otherButtonTitles: nil];
[alert show];
return;
}
I have searched SO and Google and found nothing that is specific to my issue. What am I doing wrong?
Are you testing this on a real device or the simulator? wait_fences: failed to receive reply usually means something bad happened with the debugger's connection to your device, or that you sat at a breakpoint for a really long time and it timed out. Are you sure that the code only executes once, and that nothing else could call that method? Stick breakpoints in your if statement and in your displayAlert:andData: method and see what happens. Run through your logic and find all the cases when that display alert method can be called and stick breakpoints on all of them.
I found the problem: indeed I was calling it twice from different .cs files (do you see the egg on my face?). Jack Lawrence please post your answer to the question, since you hit it on the head.