Some roadblocks and tips when updating app for iOS 7

Posted in :

stlplace
Reading Time: 2 minutes

Recently I’ve worked on updating one of my app to make it works on iOS 7, and have encountered some roadblocks.

Push view controller
problem/symptom: the new view controller pushed from old view controller shows no content, on iOS 7. It works fine on iOS 6.1 (the deployment target is still iOS 6.1).

solution/diagnose: I found the following code snippets by Sourabh Kumbhar at mobinett very handy when debugging those kinds of issues.

Put the following in the viewDidload of the view controller got affected by iOS upgrade.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}

Back to the original problem. Animation problem? I did quite a few googles trying to find out if the animation change is the cause here, but to no vail. Depends on the view, fix it in viewWillAppear or use NSNotification to make sure the viewDidLoad calls after the view property gets reset (web view).

Old code
MarketDetailViewController *marketDetailViewController =
[[MarketDetailViewController alloc] initWithNibName:@"MarketDetailViewController" bundle:nil];

// Set the title of the detail page
[marketDetailViewController setTitle:product.name];

// Push the detail controller on to the stack
[self.navigationController pushViewController:marketDetailViewController animated:YES];

// Populate the details
[marketDetailViewController setLabelsForProduct:product];

-(void) setLabelsForProduct: (Market*) theProduct
{
NSLog(@"inside setLabelsForProduct, time =%@", theProduct.time);

// Set the text of the labels to the values passed in the Product object
[nameLabel setText:theProduct.name];
[manufacturerLabel setText:theProduct.city];
[detailsLabel setText:theProduct.state];
[priceLabel setText:theProduct.phone];
[quantityLabel setText:theProduct.produce];
[daysLabel setText:theProduct.days];
[self.timeLabel setText:theProduct.time];
[startDateLabel setText:theProduct.startDate];
[endDateLabel setText:theProduct.endDate];
[emailButton setTitle:theProduct.email forState:UIControlStateNormal];
[webButton setTitle:theProduct.web forState:UIControlStateNormal];
}

New code
- (void) viewWillAppear:(BOOL)animated{
NSLog(@" MarketDetailViewController::viewWillAppear");
[super viewWillAppear:animated];

[nameLabel setText:theMarket.name];
[manufacturerLabel setText:theMarket.city];
[detailsLabel setText:theMarket.state];
[priceLabel setText:theMarket.phone];
[quantityLabel setText:theMarket.produce];
[daysLabel setText:theMarket.days];
[self.timeLabel setText:theMarket.time];
[startDateLabel setText:theMarket.startDate];
[endDateLabel setText:theMarket.endDate];
[emailButton setTitle:theMarket.email forState:UIControlStateNormal];
[webButton setTitle:theMarket.web forState:UIControlStateNormal];
[self.view setAlpha:1];
}

-(void) setLabelsForProduct: (Market*) theProduct
{
NSLog(@"inside setLabelsForProduct, time =%@", theProduct.time);
...keep all those setters here...otherwise it will break iOS 6.1
theMarket = theProduct;
}

Web View
Similar idea, but I used NSNotification to fix the problem in iOS 7.

self.webViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
// Set the title of the detail page
[self.webViewController setTitle:[nameLabel text]];

[self.navigationController pushViewController:self.webViewController animated:YES];

NSLog(@"[product web] = %@", [[webButton titleLabel] text]);

// The following works in iOS 6.1, but no longer in iOS 7
//[webViewController refreshView:[[webButton titleLabel] text]];

add the following to the viewDidLoad of parent view controller
// Listen for new image uploads so that we can refresh the image wall table
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(webPageDownloaded:)
name:N_WebPageDownloaded
object:nil];

In the web view controller, viewDidload, add
[[NSNotificationCenter defaultCenter] postNotificationName:N_WebPageDownloaded object:nil];

refreshView is the same:
-(void) refreshView:(NSString*)webAddress0
{
self.webAddress = webAddress0;
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:webAddress0]]];

CGRect textFieldFrame = CGRectMake(kLeftMargin, kTweenMargin,
self.view.bounds.size.width - (kLeftMargin * 2.0), kTextFieldHeight);
UITextField *urlField = [[UITextField alloc] initWithFrame:textFieldFrame];
...some code to render the urlField, omit for the sake of readability...
[self.view addSubview:urlField];
}

// the call back being called when posting Notification
- (void) webPageDownloaded:(NSNotification *)notification
{
[self.webViewController refreshView:[[webButton titleLabel] text]];
}

Code signing
symptom: when submit to app store, it will say no valid provision profile can be found. In some cases Xcode will crash for that project. If the user tries to submit an ad-hoc package (ipa file) via Application Loader, Apple will send “invalid signature” email right away, reject that binary. And I found following solution at stackoverflow.com
old distribution provision profile no longer work, create a new one for Xcode5

One thought on “Some roadblocks and tips when updating app for iOS 7

Comments are closed.

%d bloggers like this: