Skip to content

Commit

Permalink
Merge pull request #8351 from hansemannn/TIMOB-23890-5_5_X
Browse files Browse the repository at this point in the history
[TIMOB-23890] (5_5_X) iOS: Post notification in openURL-delegate, use newer delegate for iOS9+
  • Loading branch information
cheekiatng committed Sep 12, 2016
2 parents 89c416f + 8c83f95 commit 7332307
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
29 changes: 28 additions & 1 deletion apidoc/Titanium/App/iOS/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,18 @@ events:
osver: {ios: {min: "9.0"}}
since: '5.1.0'

- name: handleurl
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 @@ -1178,7 +1190,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 @@ -424,16 +424,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

0 comments on commit 7332307

Please sign in to comment.