问题
I'm rolling out an In-House IOS App using the Enterprise development program. I'm at a stage where I have a VC that allows the user to touch a button that downloads and installs the upgrade from inside the App.
It works well. However, if the network's a little slow, the IOS prompted message thats thrown at the user "Would you like to install, such and such..." appears a little late. So, after the user has pressed the "Install" button, I disable it. However, if there user touches, "Cancel" when prompted by IOS, I do not know how to detect this.
I'm using Xcode 4.5 and IOS6.0 on several devices iPhone 3, 4 and 5.
Without giving the entire link away, the code that does the download is as follows.
- (void)actionSheet:(UIActionSheet *)modalView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
[self.IBOInstallActivityInd startAnimating];
[self enableInstallButton:NO];
self.tabBarController.tabBar.userInteractionEnabled = NO;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:APP_INSTALL_FROM]];
}
} // actionSheet:clickedButtonAtIndex
And, as I've said, is good - it works. But if the user touches "Cancel" to the prompt, I want to be able to tell. As you can see, I'm locking the user interface down. you might ask why, if an App is about to close and receive its upgrade.
Well, depending on network speed, I want to proven the user from hitting the button more than once. But, if the user cancels, I want to be in a position where I can reinitiate the user interface, enable tab bar etc...
I've crawled the Web, found nothing! And, I guess the answer is probs on the Apple site, as good as it is. But, it takes a damned lot of reading.
Has anyone got any ideas at all?
回答1:
I don't know how to capture the cancel action, but I can tell you how we handle this situation.
Every build that we compile has a specific revision built into it, which we also embed in the plist file on our server. Our app compares the two version numbers to determine whether or not an update is available (versions don't match, which allows us to rollback too).
In your case, what you could do is simply have that VC verify the server every X seconds and refresh the state. If they take the upgrade, they'll be booted from the app, and if they don't then the refresh will make the button enabled again.
Simpler solution: Only run this query when they navigate to the VC. So if they cancel they'll have to exit the VC and reenter.
Here's what parsing the plist file looks like for us:
NSString *localCopyPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
localCopyPath = [localCopyPath stringByAppendingPathComponent:@"MDM_SERVER.plist"];
NSFileManager *fileManager = [[NSFileManager alloc] init];
BOOL created = [fileManager createFileAtPath:localCopyPath contents:plistData attributes:nil];
if (created) {
NSDictionary *fullDict = [NSDictionary dictionaryWithContentsOfFile:localCopyPath];
if (fullDict) {
NSArray *a = [fullDict objectForKey:@"items"];
NSDictionary *mdmDict = [a objectAtIndex:0];
NSDictionary *metaDict = [mdmDict objectForKey:@"metadata"];
// String of format "1.0.1779"
NSString *serverFullVersion = [metaDict objectForKey:@"bundle-version"];
// We will always compare on the last digit
NSUInteger lastPeriod = [serverFullVersion rangeOfString:@"." options:NSBackwardsSearch].location;
if (NSNotFound != lastPeriod && [serverFullVersion length] > lastPeriod) {
// update the time when we found an answer
mdmCheckedAt = [NSDate date];
NSString *serverSvnRevision = [serverFullVersion substringFromIndex:(lastPeriod + 1)];
// the big test - if our own svn version is different, then load the
// URL to tell iOS to upgrade ourself
if (![kRevisionNumber isEqualToString:serverSvnRevision]) {
// Your Code HERE
来源:https://stackoverflow.com/questions/13345283/does-anyone-know-how-to-detect-if-a-user-has-cancelled-an-in-app-attempt-to-in