Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24266] iOS: Be able to receive native delegates from app to native modules / Hyperloop

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-03-23T17:44:48.000+0000
Affected Version/sn/a
Fix Version/sRelease 7.3.0
ComponentsHyperloop, iOS
Labelsn/a
ReporterHans Knöchel
AssigneeHans Knöchel
Created2016-12-31T15:51:05.000+0000
Updated2018-07-17T15:20:22.000+0000

Description

We are currently lacking support for a "non-hacky" solution to ping native modules / hyerloop modules about global app delegates. Example use-cases: - Push notification delegates - Background service delegates - URL opening delegates - Lifecycle delegates We could either achieve this by sending notifications using the NSNotificationCenter or by writing a delegate that is called by our core and implemented by other modules that want to use it. Both solutions require a core-SDK change, rather than CLI/Hyperloop changes. I would prefer the latter solution, since it's more transparent clear to the developer and easier to extend. Before implementing anything of this, we should scope the impact on the current SDK and the required delegates to be exposed.

Comments

  1. Hans Knöchel 2017-10-16

    PR (titanium_mobile/master): https://github.com/appcelerator/titanium_mobile/pull/9761 PR (titanium_mobile/7_1_X): https://github.com/appcelerator/titanium_mobile/pull/9849 PR (hyperloop.next/master): https://github.com/appcelerator/hyperloop.next/pull/267 Test-Case:

    Create a native iOS-module (make sure to select the SDK compiled before)

    Go to the module implementation and connect to the delegate (e.g. inside create the following method):

       - (void)_configure
       {
         [super _configure];
         [[TiApp app] registerApplicationDelegate:self];
       }
       
       - (void)_destroy
       {
         [super _destroy];
         [[TiApp app] unregisterApplicationDelegate:self];
       }
       

    Add a native delegate method, e.g.

       - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
       {
         NSLog(@"[INFO] Hey there!");
       }
       

    Build the module, it should work properly

  2. Hans Knöchel 2018-01-11

    New guide: https://wiki.appcelerator.org/display/guides2/iOS+modules%3A+Use+native+UIApplication+delegates+in+Hyperloop+and+native+modules
  3. Nirmal 2018-01-14

    Will only native modules have access to these delegate events? A guide to bring this into JS (Ti controller) would be helpful.
  4. Hans Knöchel 2018-01-19

    Hyperloop example (will require Titanium 7.1.0 and Hyperloop 3.1.0):
       var TiApp = require('Titanium/TiApp');
       var UIApplicationDelegate = require('UIKit').UIApplicationDelegate;
       
       var TiAppApplicationDelegate = Hyperloop.defineClass('TiAppApplicationDelegate', 'NSObject', UIApplicationDelegate);
       
       TiAppApplicationDelegate.addMethod({
         selector: 'application:didFinishLaunchingWithOptions:',
         instance: true,
         returnType: 'BOOL',
         arguments: [
           'UIApplication',
           'NSDictionary'
         ],
         callback: function(application, options) {
           if (this.didFinishLaunchingWithOptions) {
             return this.didFinishLaunchingWithOptions(application, options);
           }
           return true;
         }
       });
       
       var applicationDelegate = new TiAppApplicationDelegate();
       
       // Called when the application finished launching. Initialize SDK's here for example
       applicationDelegate.didFinishLaunchingWithOptions = function(application, options) {
         return true
       };
       
       TiApp.app().registerApplicationDelegate(applicationDelegate);
       
    [~Nirmalkumar_Patel] We have a [guide](https://wiki.appcelerator.org/display/guides2/iOS+modules%3A+Use+native+UIApplication+delegates+in+Hyperloop+and+native+modules) ready for the release :-). You can test it today if you manually build the SDK from the above pull-request and update the "titanium.js" (located in modules/iphone/hyperloop/3.0.1/hooks/node_modules/hyperloop-metabase/templates/builtins/titanium.js and add this property:
       applicationDelegate: {
       	name: 'applicationDelegate',
       	type: {
       		type: 'id',
       		encoding: '@',
       		value: 'id'
       	}
       }
       
  5. Jan Vennemann 2018-01-22

    [~hknoechel], as i understand it, this only allows to set one delegate. What if multiple modules want to make use of this feature? Wouldn't the modules override each others delegates and only the last module has its delegate method called? The same would then apply to Hyperloop, of course.
  6. Hans Knöchel 2018-01-22

    [~jvennemann] You are right, I will adjust the PR to make it more flexible for multiple hook-ins.
  7. Hans Knöchel 2018-03-21

    For the watchers of this ticket: You can use this changes today by using the [Hyperloop 3.1.0 Beta 1](https://github.com/appcelerator-modules/hyperloop-builds/releases) and latest Titanium master (appc ti sdk install -b master).
  8. Hans Knöchel 2018-05-17

    For all developers who can't wait for the next stable release: I have compiled a custom "7.1.2" that is basically a 7.1.1.GA + the commits from this ticket. Download [here](https://www.dropbox.com/s/enfatxsle7o1d3a/mobilesdk-7.1.2-osx.zip?dl=1)!
  9. Eric Wieber 2018-07-17

    Verified changes are in SDKs 7.3.0.v20180711185043 & 7.4.0.v20180715180240

JSON Source