Skip to content

Commit

Permalink
fix(ios): callback not invoked if missing options dictionary in Ti.Pl…
Browse files Browse the repository at this point in the history
…atform.openURL (#11655)

Fixes TIMOB-27861
  • Loading branch information
vijaysingh-axway committed May 5, 2020
1 parent 707259b commit 19fc45d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 8 deletions.
2 changes: 1 addition & 1 deletion iphone/Classes/PlatformModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ READONLY_PROPERTY(NSString *, version, Version);
JSExportAs(openURL,
-(BOOL)openURL
: (NSString *)url withOptions
: (id)options andCallback
: (JSValue *)options andCallback
: (JSValue *)callback);

@end
Expand Down
14 changes: 7 additions & 7 deletions iphone/Classes/PlatformModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "PlatformModule.h"
#import "TiPlatformDisplayCaps.h"
#import "TiUtils+Addons.h"
#import <TitaniumKit/JSValue+Addons.h>
#import <TitaniumKit/TiApp.h>

#import <mach/mach.h>
Expand Down Expand Up @@ -295,17 +296,16 @@ - (NSNumber *)totalMemory
}
GETTER_IMPL(NSNumber *, availableMemory, AvailableMemory);

- (BOOL)openURL:(NSString *)url withOptions:(id)options andCallback:(JSValue *)callback
- (BOOL)openURL:(NSString *)url withOptions:(JSValue *)options andCallback:(JSValue *)callback
{
NSURL *newUrl = [TiUtils toURL:url proxy:self];
BOOL result = NO;

// iOS 10+
NSMutableDictionary *optionsDict = [NSMutableDictionary dictionary];
if ([options isKindOfClass:[NSDictionary class]]) {
optionsDict = (NSMutableDictionary *)options;
} else if ([options isKindOfClass:[JSValue class]]) {
callback = (JSValue *)options;
NSDictionary *optionsDict = @{};
if ([options isFunction]) {
callback = options;
} else if ([options isObject]) {
optionsDict = [options toDictionary];
}

if (newUrl != nil) {
Expand Down
8 changes: 8 additions & 0 deletions iphone/TitaniumKit/TitaniumKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
4A175277218B64E70094C7B6 /* KrollTimerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A175275218B64E70094C7B6 /* KrollTimerManager.m */; };
4AF8DEEB1F0C27D6006270E1 /* libAPSAnalytics.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DBA197501F0C20E300B12D31 /* libAPSAnalytics.a */; };
4AF8DEEC1F0C27D9006270E1 /* libAPSHTTPClient.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DBA197511F0C20E300B12D31 /* libAPSHTTPClient.a */; };
B106A6FD24535CB800B1305E /* JSValue+Addons.h in Headers */ = {isa = PBXBuildFile; fileRef = B106A6FB24535CB800B1305E /* JSValue+Addons.h */; settings = {ATTRIBUTES = (Public, ); }; };
B106A6FE24535CB800B1305E /* JSValue+Addons.m in Sources */ = {isa = PBXBuildFile; fileRef = B106A6FC24535CB800B1305E /* JSValue+Addons.m */; };
B7624B6C216663C7000C365A /* ObjcProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = B7624B6A216663C7000C365A /* ObjcProxy.h */; settings = {ATTRIBUTES = (Public, ); }; };
B7624B6D216663C7000C365A /* ObjcProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = B7624B6B216663C7000C365A /* ObjcProxy.m */; };
DB1596592075389000292B19 /* APIModule.m in Sources */ = {isa = PBXBuildFile; fileRef = DB1596572075389000292B19 /* APIModule.m */; };
Expand Down Expand Up @@ -181,6 +183,8 @@
/* Begin PBXFileReference section */
4A175274218B64E70094C7B6 /* KrollTimerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KrollTimerManager.h; sourceTree = "<group>"; };
4A175275218B64E70094C7B6 /* KrollTimerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KrollTimerManager.m; sourceTree = "<group>"; };
B106A6FB24535CB800B1305E /* JSValue+Addons.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JSValue+Addons.h"; sourceTree = "<group>"; };
B106A6FC24535CB800B1305E /* JSValue+Addons.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "JSValue+Addons.m"; sourceTree = "<group>"; };
B7624B6A216663C7000C365A /* ObjcProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjcProxy.h; sourceTree = "<group>"; };
B7624B6B216663C7000C365A /* ObjcProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjcProxy.m; sourceTree = "<group>"; };
DB1596572075389000292B19 /* APIModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APIModule.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -554,6 +558,8 @@
DB15FC5E1F0A84C900A82C45 /* Webcolor.m */,
DB15FC471F0A83A700A82C45 /* WebFont.h */,
DB15FC481F0A83A700A82C45 /* WebFont.m */,
B106A6FB24535CB800B1305E /* JSValue+Addons.h */,
B106A6FC24535CB800B1305E /* JSValue+Addons.m */,
);
name = API;
path = Sources/API;
Expand Down Expand Up @@ -691,6 +697,7 @@
DB15FCA81F0A866300A82C45 /* TiRect.h in Headers */,
DB15FC891F0A859800A82C45 /* TiExceptionHandler.h in Headers */,
DB15FD281F0A93A900A82C45 /* TiFilesystemFileStreamProxy.h in Headers */,
B106A6FD24535CB800B1305E /* JSValue+Addons.h in Headers */,
DB15FCB81F0A874F00A82C45 /* TopTiModule.h in Headers */,
DB15FC3B1F0A833100A82C45 /* KrollMethodDelegate.h in Headers */,
DB15FC391F0A833100A82C45 /* KrollMethod.h in Headers */,
Expand Down Expand Up @@ -819,6 +826,7 @@
DB15FC701F0A84FD00A82C45 /* TiBlob.m in Sources */,
DB15FD0D1F0A894000A82C45 /* TiWindowProxy.m in Sources */,
DB15FC991F0A862000A82C45 /* TiPoint.m in Sources */,
B106A6FE24535CB800B1305E /* JSValue+Addons.m in Sources */,
DB1596632075461400292B19 /* SBJSON.m in Sources */,
DB15FCA11F0A863B00A82C45 /* LayoutConstraint.m in Sources */,
DB15FC9D1F0A862D00A82C45 /* ListenerEntry.m in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/JSValue+Addons.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2018-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#import <JavaScriptCore/JavaScriptCore.h>

NS_ASSUME_NONNULL_BEGIN

@interface JSValue (Addons)

@property (readonly) BOOL isFunction;

@end

NS_ASSUME_NONNULL_END
26 changes: 26 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/JSValue+Addons.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2018-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#import "JSValue+Addons.h"

@implementation JSValue (Addons)

- (BOOL)isFunction
{
if (!self.isObject) {
return NO;
}

JSContextRef context = self.context.JSGlobalContextRef;
JSObjectRef object = JSValueToObject(context, self.JSValueRef, NULL);
if (object == NULL) {
return NO;
}
return JSObjectIsFunction(context, object);
}

@end
1 change: 1 addition & 0 deletions iphone/TitaniumKit/TitaniumKit/TitaniumKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ FOUNDATION_EXPORT const unsigned char TitaniumKitVersionString[];
#import <TitaniumKit/APSAnalytics.h>
#import <TitaniumKit/APSHTTPClient.h>
#import <TitaniumKit/ImageLoader.h>
#import <TitaniumKit/JSValue+Addons.h>
#import <TitaniumKit/Mimetypes.h>
#import <TitaniumKit/NSData+Additions.h>
#import <TitaniumKit/ObjcProxy.h>
Expand Down
23 changes: 23 additions & 0 deletions tests/Resources/ti.platform.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions'),
utilities = require('./utilities/utilities');

describe('Titanium.Platform', function () {

it.ios('#openURL(url, callback)', function (finish) {
Ti.Platform.openURL('randomapp://', e => finish());
});

it.ios('#openURL(url, options, callback)', function (finish) {
Ti.Platform.openURL('randomapp://', {}, e => finish());
});

});

0 comments on commit 19fc45d

Please sign in to comment.