iOS-Xcode: ProgressHUD at the beginning of the app - svprogresshud

First of all sorry about my english, it´s not my native language.
I am developing an iOS app that collects data from a JSON and displays them in a table. Everything works correctly . My problem is that JSON has many data and the app takes several seconds until it show the data. So , I need to put a charge indicator to alert the user to wait until the application has loaded the data. To use the charging indicator I downloaded Seller SVProgressHUD :
https://github.com/samvermette/SVProgressHUD
I've integrated SVProgressHUD into my application but I can not make it work as I want.
In my application I have a class AppDelegate and a class MasterViewController (where I load JSON data , populate the tableView and show the tableView)
What I want is when the application starts his executions it shows the SVProgressHUD with the text "Loading" and when the tableView with all the data appears, the SVProgressHUD dissapears.
For this, I added this line of code in my class AppDelegate in the method didFinishLaunchingWithOptions:
[SVProgressHUD showWithStatus:#"Cargando" maskType:SVProgressHUDMaskTypeBlack];
And in my class MasterViewController, in the viewDidLoad method I have added this line of code:
[SVProgressHUD dismiss];
After adding these lines of code, my application runs as ever and doesn't show charging indicator.
I think it may be because in the didFinishLaunching still no loaded view where you can show charging indicator but I don´t know what is the code that I have to add to make it works.
A greeting and thanks for the help .

Place this code before you send your json request for fetching data
[SVProgressHUD showWithStatus:#"Updating" maskType:SVProgressHUDMaskTypeBlack];
I have used afnetworking in my application. So when it returns success, i dismiss the SVProgressHUD.
[client postPath:#"xyz.com/abcd" parameters:params1 success:^(AFHTTPRequestOperation *operation, id responseObject) {
[SVProgressHUD dismiss];
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[SVProgressHUD dismiss];
}];
Hope it is helpful to you.
Thanks

Related

Why is WKInterfaceLabel text not refreshing

The WatchApp receives data from the iPhone.
I refresh the label text with the data received, nothing happens, the UI is not refreshing.
Other threads suggested pushing it to the main thread and that seems to do nothing either.
Any thoughts most welcome.
-(void)session:(nonnull WCSession *)session didReceiveApplicationContext:(nonnull NSDictionary *)applicationContext
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.lblTitleBorH setText:#"test"];
});
}
Are you using
[*your session* updateApplicationContext:*your dictionary* error:nil];
correctly?
try putting a NSLog inside your above didReceiveApplicationContext code and see if it is printing anything out.
In my case, when I tried to refresh the UI, I found that the outlet references were nil. The problem was caused by two interfaces on the storyboard, belonging to the same WKInterfaceController class.
When I assigned the second screen interface to another WKInterfaceController class it worked fine.
remember to call the UI objects from the main thread by using
dispatch_async(dispatch_get_main_queue(), ^{
...
});
or by using methods like performSelectorOnMainThread: withObject: waitUntilDone:

iOS7 sending SMS from inside the app has a misaligned modal view

I'm writing an app where I need to allow the user sending SMS from within the app.
It works fine on iOS6 but not on iOS7.
When I'm trying to send a text message, the modal view appears but there is a strange gap between the "to" field and the list of possible contacts.
After selecting the first contact, the "to" field slides up and disappears and then I see past messages and my new message but with the same gap again.
I'm attaching two images showing the issue:
Here is the code I'm using:
if([MFMessageComposeViewController canSendText]) {
NSArray *recipents = nil;
NSString *message = #"Let's go";
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipents];
[messageController setBody:message];
[self presentModalViewController:messageController animated:YES];
}
Please tell me if know you know how to fix this issue.
Thanks!
Additional info:
This bug only happens in iOS 7.x not in in iOS 6.x
Also, if I use the MFMailComposeViewControllerDelegate to send emails, it works just fine (although they are both implemented by MessageUI.h)...
Ok, I figured it out.
The issue happens because I have a custom UINavigationController.
In my AppDelegate, I had the following code:
UIImage *navBarImage = [UIImage imageNamed:#"BarIos7.png"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
Once I removed it, everything started working fine.

Get ADInterstitialAd to load more often on iPad: possible?

I'm testing my iAd on my iPad, and I can't seem to get my ADInterstitialAd to load very often.
It does run occasionally but most of the time the first method below is called
- (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError*)error{
NSLog(#"Ad Failed");
//[self cycleInterstitial];
}
However when I try to reload it upon failing.(see below method) It just fails over and over. I dont see why apple would let it just fail in a testing environment. I have read that the fill rate can be low, but it seems really low just for a test iPad app.
- (void)cycleInterstitial{
// Clean up the old interstitial...
interstitial.delegate = nil;
[interstitial release];
// and create a new interstitial. We set the delegate so that we can be notified of when
interstitial = [[ADInterstitialAd alloc] init];
interstitial.delegate = self;
}
Can anyone please advise? Thanks!
No, sorry. Apple is solely responsible for the fill rate of iAds, including interstitial iAds for iPad. As developers and users, we do not have any direct control over this.

customize an action of iphone home button to submit score in gamecenter

i have a button in my app a button that submit score to gamecenter and works.
this is the code:
-(void)subScore{
GKScore *scoreRepoter = [[[GKScore alloc] initWithCategory:#"123456"] autorelease];
scoreRepoter.value=100;
[scoreRepoter reportScoreWithCompletionHandler:^(NSError *error) {
if (error!=nil) {
NSLog(#"errr submitting");
}else
NSLog(#"ok!");
}];
now i'd like to submit score before app is closed with home button.
i thought to customize an action of home button (if it is possible)
or perhaps i make the same line of code in viewDidUload...or something like that...
will i be sure that that action will be performed before unloading the app?
i should make that code in dealloc method?
thanks
You can't customize behaviour of Home button directly, but iOS provides some methods in your application's delegate, by which you can control lifecycle of the application.
Method called right before the application goes to background is applicationWillResignActive: in your application's delegate (usually this method is located in AppDelegate.m file).
I think you can get needed effect by calling your method like that:
- (void)applicationWillResignActive:(UIApplication *)application {
[mygame subScore];
}
Also please note that iOS has time limit of execution for this method: you must do all saving-the-game work in less that five seconds or your application will be killed.

Instructing an app on which view to open on load?

I am trying to instruct my app to open a certain view, depending on whether the user has already created a user profile on my database.
so basically -
- (void) viewWillAppear:(BOOL)animated {
//all my ASIHTTPRequest code here
//blah blah blah
NSString *responseString = [request responseString];
if ([responseString isEqualToString:#"noexistingdata"])
{
FriendsViewController *friendsview = [[FriendsViewController alloc] initWithNibName:nil bundle:nil];
//SOMETHING NEEDS TO GO HERE TO MAKE THIS WORK!
} else if ([responseString isEqualToString:#"success"])
{
//do whatever
}
}
I just want the most basic code for changing a view... I would try using IBAction, but obviously that won't work as this is in a void for the app's launch (rather a response to a button the user presses), also thought about void in a void, which also did not work.
So basically what I need is:
Launch App > App receives response from my server > (IF RESPONSE = "THIS", LOAD VIEW "X") (IF RESPONSE = "THAT", LOAD VIEW "Y")
Anyone have a clue?
PS: would it be better to list this is applicationDidFinishLaunching?
-viewWillAppear: is called just before a view is displayed. That's probably not a great time to a) run some synchronous network request and b) load another view controller.
I'd suggest having the application delegate create a view controller who's view just displays a message, like "Connecting to server" or "Retrieving user credentials" or whatever. You might add an animated spinner to let the user know that they're supposed to wait, if that's all they're allowed to do at this point. Then, after the view is displayed, such as in that controller's -viewDidLoad method, start an asynchronous network connection to talk to the server. When you get back a response, decide which view controller to instantiate next, and do that.