应用程序宣布新的更新

时间:2018-02-17 07:07:30

标签: ios objective-c

我正在尝试让应用宣布新的更新存在... 我收到一条新警报的通知,但问题是我无法控制它..它只是在我更改了" appinfo.plist"中的版本后才通知不间断。这是在github 它就像这样

- (void)checkVersion {
    NSString *rawgitHistory = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"appinfo" ofType:@"plist"] encoding:NSUTF8StringEncoding error:nil];
    __block NSArray *gitHistory = [rawgitHistory componentsSeparatedByString:@"\n"];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), ^{
        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/dev/myapp/master/appinfo.plist"]];
        // User isn't on a network, or the request failed
        if (data == nil) return;

        NSString *gitCommit = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

        if (![gitHistory containsObject:gitCommit]){
            dispatch_async(dispatch_get_main_queue(), ^{
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Update Available!" message:@"An update is available! Please visit download the latest IPA!" preferredStyle:UIAlertControllerStyleAlert];
                [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
                [self presentViewController:alertController animated:YES completion:nil];
            });
        }
    });
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self checkVersion];
}

appinfo.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Version</key>
    <string>1.0.4.1</string>
</dict>
</plist>

2 个答案:

答案 0 :(得分:0)

你可以让这更容易。您可以执行以下操作,而不是比较plist文件:

检查应用程序的内部版本号,并在Web服务中存储最新的内部版本号,然后比较这两个值。如果应用的内部版本号小于Web服务中的内部版本号,则显示警报。

-(void)checkVersion {

   //Get the current installed build number
   NSString *currentBuildID = [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey];
   __block NSInteger currentBuildNumber = currentBuildID.integerValue;

    dispatch_async(dispatch_queue_create("buildChecker", NULL), ^{

       NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"your url to get build number"]];
       // User isn't on a network, or the request failed
       if (data == nil) return;

       NSString *latestBuild = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
       //Compare the latest build number with app's build number
       if (currentBuildNumber < latestBuild.integerValue){
           dispatch_async(dispatch_get_main_queue(), ^{
               UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Update Available!" message:@"An update is available! Please visit download the latest IPA!" preferredStyle:UIAlertControllerStyleAlert];
               [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
               [self presentViewController:alertController animated:YES completion:nil];
          });
       }
   });
}



您可以在常规&gt;构建
enter image description here

下的目标窗格中设置应用的内部版本号

答案 1 :(得分:0)

@RestController
@RequestMapping("/api")
@Transactional
public class SomethingResource {

    private final SomethingRepository somethingRepository;

    public SomethingResource(SomethingRepository somethingRepository) {
        this.somethingRepository = somethingRepository;
    }

    @PostMapping("/somethings")
    public Something createSomething(@RequestBody Something something) throws URISyntaxException {
        Something result = somethingRepository.save(something);
        somethingRepository.refresh(result);
        return result;
    }
}