UIAlertView is not visible after bring app to foreground - objective-c

I'm working on a some iOs project. In this project, i have a process:
User register himself in registration page
When he press "Register", another page is showed (via NavigationControler, with progress idndicator and 'Please Wait' message.)
After get response from server, some message in UIAlertView is show
When user press "OK" on alert, it's moved to next (when everything is ok), or previous (when something go wrong) page.
In most case, this flow works. But in sometimes (not always), when user send application to background/lock the screen while process indicator is on, and then turn app back to active state, UIAlertView is not shown. But, then, if user again send app to background and bring it back, message is visible.
Because interaction with UIAlertView is needed to continue, it's a problem. I cannot request from user a knowledge, that if no message is visible in this moment, they should turn app back and front again. I don't know why it is happen, and how to avoid this behavior. Can you help me?

When your app is in background you can give the local notification. so according to you if alertview is not coming but still you want that user should know about that something is happen or something is wrong then you can directly use local Notifications.
here is the code -
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = self.datePicker.date;
localNotification.alertBody = self.messageField.text;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1;
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:#"Object 1", #"Key
1", #"Object 2", #"Key 2", nil];
localNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
So when local notification generate user can know about that. And you can navigate the user to directly to application. on clicking off local notification alert. locasl notification alert will come automatically.
here the link for the more details-
http://www.iostipsandtricks.com/ios-local-notifications-tutorial/

Related

Open account preferences panel in front of actual modal window in cocoa

I have a Mac app with a preferences window. The preferences window is opened modally
-(IBAction)displayPreferencesWindow:(id)sender{
if (!pc) {
pc = [[PreferencesController alloc] initWithWindowNibName:#"PreferencesController"];
pc.delegate = self;
}
NSWindow *pcWindow = [pc window];
[NSApp runModalForWindow: pcWindow];
[NSApp endSheet: pcWindow];
[pcWindow orderOut: self];
}
In the preferences Window I have a button that opens the account preferences panel
- (IBAction)openSystemPrefs:(id)sender {
[[NSWorkspace sharedWorkspace] openFile:#"/System/Library/PreferencePanes/Accounts.prefPane"];
}
The problem is that the account preferences panel does not open in front of the actual Window. How can I achieve this?
This is kind of weird, and goes against the comments in the header, but try using this instead:
- (BOOL)openFile:(NSString *)fullPath withApplication:(NSString *)appName andDeactivate:(BOOL)flag;
From the comments there:
Open a file at some path. If you use the variant without the
withApplication: parameter, or if you pass nil for this parameter, the
default application is used. The appName parameter may be a full path
to an application, or just the application's name, with or without the
.app extension. If you pass YES for andDeactivate:, or call a variant
without this parameter, the calling app is deactivated before the new
app is launched, so that the new app may come to the foreground unless
the user switches to another application in the interim. Passing YES
for andDeactivate: is generally recommended.
So it sounds like your app should be deactivating (since you're calling a variant without the andDeactivate: parameter) but I would try explicitly using the variant with that parameter, just to be sure.
Empirically, it appears that the launched application will not activate if the launching application is presenting modal UI, at least not when using the NSWorkspace API. I was able to hack something up using AppleScript that appears to achieve the desired results:
- (IBAction)doStuff:(id)sender
{
[[NSWorkspace sharedWorkspace] openFile:#"/System/Library/PreferencePanes/Accounts.prefPane"];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSString* s = #"tell application \"System Preferences\" to activate";
NSAppleScript* as = [[[NSAppleScript alloc] initWithSource: s] autorelease];
NSDictionary* error = nil;
if ([as compileAndReturnError: &error])
{
(void)[as executeAndReturnError: &error];
}
});
}
I dispatched it to the background queue because it takes a few hundred milliseconds to compile and run the AppleScript and it's a little conspicuous if done synchronously (the button stays highlighted longer than you expect).
If you were feeling really masochistic, you could probably get the script compiling phase out of it (i.e. quicker) by conjuring up the equivalent AppleEvents and sending them directly, but this appeared to achieve the desired effect, even while presenting modal UI in the launching application.

How to display iOS 6 Facebook alert view without first showing SLComposeViewController

In iOS 6, when you create an SLComposeViewController and show it with presentViewController and you have not called isAvailableForServiceType first, you will get the "No Facebook Account" alert view which gives the user an opportunity to set up their account in Settings.
Unfortunately it also shows the native Facebook posting dialog in the background as well.
I would like to have a cleaner experience than popping up two dialogs at the same time, so is there a way to only show the "No Facebook Account" dialog on its own after checking availability with isAvailableForServiceType?
Here's basically what I'd like to do:
// Check to see if the user has a Facebook account set up...
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *vc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler completionBlock = ^(SLComposeViewControllerResult result){
// do something when complete...
};
[vc setCompletionHandler:completionBlock];
[vc setInitialText:#"Intital text..."];
[self presentViewController:vc animated:YES completion:nil];
} else {
// No Facebook account configured yet,
// so show "No Facebook Account" alert view here.
}
Is this even possible, or will I just need to show a vanilla UIAlertView that tells the user to go to the Settings app and set up their Facebook Account?
BTW, I'm also guarding that block with a call that determines if this device even supports the use of SLComposeViewController, and if not, uses the Facebook SDK instead...
I wish it could be easy!! For now i was able to call the composeViewControllerForServiceType: method even without the account setup so it will show the alert with the settings button, hide the view but i couldn't be able to hide the keyboard!! Maybe you could find a way to reset the UITextFieldDelegate or whatevere esle to not show the keyboard...but I'm not sure! Let me know if you could figure it out!

iOS 6 local notifications fail when the phone is locked with app open

I have an app with basic alarm functionality. In my applicationWillResignActive: method I have it setup to create notifications to set off the alarm. This works pretty great, and I believe this is the proper way to do it (let me know if you think there is a better way).
Only in the specific situation, ONLY ON iOS 6, when the application is not "quit" (the home button is never pressed) but the user merely locks the phone or the phone auto locks, the notifications don't go off.
I have traced through the code, and the notifications are indeed being created and it worked perfectly in iOS 5.
Here is my code:
- (void)applicationWillResignActive:(UIApplication *)application
{
[UIApplication sharedApplication].idleTimerDisabled = NO;
[alarm setupForBackground];
if ([alarm isRunning]) {
[alarm stop];
}
}
Here is the notification creation method:
- (void)setupForBackground
{
UILocalNotification* alarmNotification = [[UILocalNotification alloc] init];
if (alarmNotification) {
alarmNotification.fireDate = alarmDate;
alarmNotification.timeZone = [NSTimeZone defaultTimeZone];
alarmNotification.repeatInterval = 0;
alarmNotification.soundName = #"NotificationSound.aif";
[[UIApplication sharedApplication] scheduleLocalNotification:alarmNotification];
}
}
I have been searching for an answer for a while, and I could not find anything stating something about notification changes. Thanks for any help.
I have a semi-solution. Apparently if you add an AlertBody to the notification, then it works.
My belief is that this is a bug in iOS 6. As I mentioned it worked in iOS 5, the documentation makes no mention of having such a requirement, and the notification does work without the AlertBody if the application is quit (the home button is pressed).
Still curious to see if my understanding is correct and if I should file a bug report with Apple.
Thoughts anybody?

iOS strange bug with button and view change

That's the first time i post on this site.
I explain, i have to work on an already advanced project in ios.
I'm new in objective-c and it's a quite strange language when you come from java.
I have a strange issue.
In the app there is a login screen, you put mail and pass, click on a button and you go on the main view. It's work perfectly.
What i want to do is autologin. I use keychains for that, store it, retrieve it, populate my user and pass with. It's works perfectly.
If my user click on the login button it's also work perfectly.
But if i call the function myself with the code, it doesn't change the view. I can't understand why.
I put here the code where i think the change is called.
if ([result isEqualToString:#"1"]) {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:Email.text forKey:#"email"];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Welcom back to FriendsCam!" message:#"Start sharing your video" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
//Email.text = nil;
//Password.text = nil;
UIStoryboard *MainStoryboard_iPhone=[UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
self.view.window.rootViewController=[MainStoryboard_iPhone instantiateInitialViewController];
So this code is in a function who is called by the functions called when the button login is pressed if all field are correctly fill.
It work when a user manually click on the button but not when i call the button's function myself in code but the alert "welcome back" of good login show in both cases. it's only the jump in the storyboard who is broken.
Can someone explain why ? It will be very kind.
Ok i find the solution.
I was firing my method to quickly, something related with loading time of the view i think.
I delay my call with a nstimer and all work perfectly.

How to handle mountain lion notifications clicks

I just wanted to add some notifications to Gyazo app.
I finally able to send notifications to the notifications center http://korniltsev.ru/p/jz6m3Nm.png
however when i click on it and the app is not launched it launches in some strange way:
it shows empty window(even if i set it visibleAtLaunch to 0) and nothing happens;http://korniltsev.ru/p/jz6mvk0.png
the code i'm trying to use is here:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSUserNotification * clicked = [[aNotification userInfo]
objectForKey:NSApplicationLaunchUserNotificationKey];
if (clicked){
[NSApp terminate:self];
return;
}
...
I send notifications like this
NSUserNotificationCenter *manager = [NSUserNotificationCenter defaultUserNotificationCenter];
NSUserNotification *urlNotification = [[NSUserNotification alloc]init];
[urlNotification setTitle:appName];
[urlNotification setInformativeText:url];
[manager deliverNotification:urlNotification];
What am i doing wrong?
[NSApp terminate:self] has a lot of side effects. Are you sure these side effects are not creating your blank window? Have you tried calling [NSApp terminate:self] immediately in applicationDidFinishLaunching and making sure you application quits cleanly in every case? If it does not you will likely have to look at what you are doing in your application's document controller (if you have one) and applicationShouldTerminate.