iOS Question Check if my IOS application is updated

Filippo

Expert
Licensed User
Longtime User
Hi,

is it possible to implement something like this in B4i, or is there already something comparable?
I didn't find anything in any case.

 

Filippo

Expert
Licensed User
Longtime User
I guess that you have some settings file. Add a version field. If it is lower than the current version then show the message and update the settings file.
Hi Erel,

I already know that you can do it this way.
But what I want is what you can do with this code.
B4X:
-(BOOL) needsUpdate
{
    NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString* appID = infoDictionary[@"CFBundleIdentifier"];
    NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
    NSData* data = [NSData dataWithContentsOfURL:url];
    NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

   if ([lookup[@"resultCount"] integerValue] == 1)
   {
       NSString* appStoreVersion = lookup[@"results"][0][@"version"];
       NSString* currentVersion = infoDictionary[@"CFBundleShortVersionString"];
       if (![appStoreVersion isEqualToString:currentVersion])
       {
           NSLog(@"Need to update [%@ != %@]", appStoreVersion, currentVersion);
           return YES;
       }
    }
    return NO;
}
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Use iHttpUtils2 to get this data. More information about this API: https://stackoverflow.com/a/24839038/971547
Thanks @Erel very useful!

B4X:
Sub Button1_Click
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("http://itunes.apple.com/lookup?id=6478831936")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim parser As JSONParser
        parser.Initialize(j.GetString)
        Dim jRoot As Map = parser.NextObject
        
        Dim results As List = jRoot.Get("results")
        For Each colresults As Map In results
            
            Wait For (GetImage(colresults.Get("artworkUrl100"))) complete (Logo As B4XBitmap)
            xiv_AppLogo.Bitmap = Logo
            
            xlbl_AppName.Text = colresults.Get("trackName") & " V" & colresults.Get("version")
            xlbl_AppDescription.Text = colresults.Get("description")
                
        Next
        
    End If
    j.Release
End Sub

Private Sub GetImage(Url As String) As ResumableSub
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(Url)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Return j.GetBitmap.As(B4XBitmap)
    End If
    j.Release
    Return Null
End Sub
 

Attachments

  • B4J Test Example.zip
    2.7 KB · Views: 100
Upvote 1

Filippo

Expert
Licensed User
Longtime User
Very interesting. Is there something similar for the Play Store too ?
Yes, but I don't know if it still works.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…