iOS Question Does main.m work in current B4i releases ?

Semen Matusovskiy

Well-Known Member
Licensed User
I found some obj-c samples to upload files in background, for example, https://github.com/sajadkhan/Background-Upload-iOS

All samples need to modify something in AppDelegate (.h/.m). So I used main.m as layout https://www.b4x.com/android/forum/threads/background-fetch-downloads.56022/ and added a property inside interface B4IMyDelegate. Surprise ... I can't access it inside OBJC and using nativeobject GetField.

Probably, I do something wrong. If so, please, show how to add a property to B4IMyDelegate.
But it looks that main.m does not work. Unlike a compiler exactly includes modified main.m into B4iProject.
 
Last edited:

Semen Matusovskiy

Well-Known Member
Licensed User
Thanx for reply.
About properties I remembered - it's not possible to add properties to existing class by normal way.
Ok, remains a question about methods.

I 'translated' OBJC-sample. NSURLSession works fine even in background and I receive messages that a task is finished.
But I don't see application:handleEventsForBackgroundURLSession: and can't understand way.

AppDelegate.m in OBJC-sample has
B4X:
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler
{
    NSLog(@"Background URL session needs events handled: %@", identifier);
    completionHandler();
}

I converted to

B4X:
#if OBJC
@end
@implementation B4IAppDelegate (SM)

- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler
{
    NSLog(@"Background URL session needs events handled: %@", identifier);
    completionHandler();
    B4I* bi = [b4i_main new].bi;
    [bi raiseUIEvent:nil event:@"application_handleeventsforbackgroundurlsession:" params:@[identifier]];
}

#End If

NSLog works fine in background (I output a response from web server). Probably, a problem in application:handleEventsForBackgroundURLSession:completionHandler: as it is. But I can't access to it (I mean no.Initialize ("B4IAppDelegate").RunMethod ("application:handleEventsForBackgroundURLSession:completionHandler:", ...). And this confuses me. What I doing wrong ?
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
NSLog(@"Background URL session needs events handled: %@", identifier);
Do you see this log message?
No. I even reduced to one task. Response is expected, return code 200.
Should say that the same happens, when I run original sample under xcode. Maybe Apple changed something (a sample was written in 2014). So I mostly confused that I can't access a method using Runmethod
 
Last edited:
Upvote 0
Top