Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-23890] iOS: Post notification in openURL-delegate, use newer delegate for iOS9+ #8346

Merged
merged 5 commits into from
Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 28 additions & 1 deletion apidoc/Titanium/App/iOS/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,18 @@ events:
osver: {ios: {min: "9.0"}}
since: '5.1.0'

- name: handleurl
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cheekiatng In case you ask why we need this here: It is triggered by https://jira.appcelerator.org/browse/TIMOB-23884 that is caused by an open Apple issue. It is both workaround until Apple fixes it as well as the future-way to receive updates from URL's that get handled by the application.

And since it used the same notification as below (kTiApplicationLaunchedFromURL), it can be used here as well.

summary: Fired when a new URL is handled by the application.
description: |
Incoming URL's can either be triggered by an external application or
links inside your <Titanium.UI.WebView> / <Modules.SafariDialog>.
properties:
- name: launchOptions
summary: The launch options that are related to opening the URL.
type: LaunchOptionsType
osver: {ios: {min: "8.0"}}
since: "6.0.0"

---
name: NotificationParams
summary: |
Expand Down Expand Up @@ -1205,7 +1217,22 @@ properties:
type: Dictionary
optional: true
since: "5.4.0"


---
name: LaunchOptionsType
summary: |
Dictionary object of parameters used to identify an incoming URL that is handled
by the application.
since: "6.0.0"
platforms: [iphone, ipad]
properties:
- name: source
summary: The application or service that triggered the handled URL.
type: String
- name: url
summary: The url that was triggered by the application or service.
type: String

---
name: UserNotificationSettings
summary: |
Expand Down
25 changes: 20 additions & 5 deletions iphone/Classes/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,31 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

// Handle URL-schemes / iOS >= 9
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
{
[launchOptions removeObjectForKey:UIApplicationLaunchOptionsURLKey];
[launchOptions setObject:[url absoluteString] forKey:@"url"];
[launchOptions removeObjectForKey:UIApplicationLaunchOptionsSourceApplicationKey];

[launchOptions setObject:[options objectForKey:UIApplicationOpenURLOptionsSourceApplicationKey] ?: [NSNull null] forKey:@"source"];

[[NSNotificationCenter defaultCenter] postNotificationName:kTiApplicationLaunchedFromURL object:self userInfo:launchOptions];

return YES;
}

// Handle URL-schemes / iOS < 9
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
[launchOptions removeObjectForKey:UIApplicationLaunchOptionsURLKey];
[launchOptions setObject:[url absoluteString] forKey:@"url"];
[launchOptions removeObjectForKey:UIApplicationLaunchOptionsSourceApplicationKey];
if(sourceApplication == nil) {
[launchOptions setObject:[NSNull null] forKey:@"source"];
} else {
[launchOptions setObject:sourceApplication forKey:@"source"];
}

[launchOptions setObject:sourceApplication ?: [NSNull null] forKey:@"source"];
[[NSNotificationCenter defaultCenter] postNotificationName:kTiApplicationLaunchedFromURL object:self userInfo:launchOptions];
return YES;
}

Expand Down
13 changes: 13 additions & 0 deletions iphone/Classes/TiAppiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ -(void)_listenerAdded:(NSString*)type count:(int)count
}
}

if ((count == 1) && [type isEqual:@"handleurl"]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didHandleURL:)
name:kTiApplicationLaunchedFromURL
object:nil];
}
}

-(void)_listenerRemoved:(NSString*)type count:(int)count
Expand Down Expand Up @@ -189,6 +195,13 @@ -(void)didReceiveApplicationShortcutNotification:(NSNotification*)info
[self fireEvent:@"shortcutitemclick" withObject:event];
}

-(void)didHandleURL:(NSNotification*)info
{
[self fireEvent:@"handleurl" withObject:@{
@"launchOptions": [info userInfo]
}];
}

#ifdef USE_TI_APPIOSSEARCHABLEINDEX
-(id)createSearchableIndex:(id)unused
{
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ extern NSString * const kTiURLUploadProgress;
extern NSString * const kTiWatchKitExtensionRequest;
extern NSString * const kTiContinueActivity;
extern NSString * const kTiApplicationShortcut;
extern NSString * const kTiApplicationLaunchedFromURL;

#ifndef TI_USE_AUTOLAYOUT
extern NSString* const kTiBehaviorSize;
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ void TiLogMessage(NSString* str, ...) {
NSString * const kTiWatchKitExtensionRequest = @"TiWatchKitExtensionRequest";
NSString * const kTiContinueActivity = @"TiContinueActivity";
NSString * const kTiApplicationShortcut = @"TiApplicationShortcut";
NSString * const kTiApplicationLaunchedFromURL = @"TiApplicationLaunchedFromURL";

#ifndef TI_USE_AUTOLAYOUT
NSString* const kTiBehaviorSize = @"SIZE";
Expand Down