From 6d45f6953ba38b2b8381fcbe6bd30a24b6aee7fd Mon Sep 17 00:00:00 2001 From: Jaime Casero Date: Tue, 15 Nov 2016 12:38:21 +0100 Subject: [PATCH 1/2] fixes https://github.com/RestComm/restcomm-ios-sdk/issues/500 --- .../restcomm-olympus/restcomm-olympus/Utils.m | 51 ++++++++++--------- .../restcomm-olympus-Info.plist | 10 ++++ 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/Examples/restcomm-olympus/restcomm-olympus/Utils.m b/Examples/restcomm-olympus/restcomm-olympus/Utils.m index 3c22a4a..986763e 100644 --- a/Examples/restcomm-olympus/restcomm-olympus/Utils.m +++ b/Examples/restcomm-olympus/restcomm-olympus/Utils.m @@ -84,14 +84,14 @@ + (void) setupUserDefaults ], }, }; - + [[NSUserDefaults standardUserDefaults] registerDefaults:basicDefaults]; } + (NSArray*)messagesForSipUri:(NSString*)sipUri { NSMutableArray *messages = [[NSMutableArray alloc] init]; - + NSUserDefaults* appDefaults = [NSUserDefaults standardUserDefaults]; if ([appDefaults dictionaryForKey:@"chat-history"] && [[appDefaults dictionaryForKey:@"chat-history"] objectForKey:sipUri]) { return [[appDefaults dictionaryForKey:@"chat-history"] objectForKey:sipUri]; @@ -106,15 +106,15 @@ + (void)addMessageForSipUri:(NSString*)sipUri text:(NSString*)text type:(NSStrin if (![appDefaults dictionaryForKey:@"chat-history"]) { return; } - + NSMutableDictionary * messages = [[appDefaults dictionaryForKey:@"chat-history"] mutableCopy]; if ([messages objectForKey:sipUri]) { aliasMessages = [[messages objectForKey:sipUri] mutableCopy]; } - + [aliasMessages addObject:[NSDictionary dictionaryWithObjectsAndKeys:text, @"text", type, @"type", nil]]; [messages setObject:aliasMessages forKey:sipUri]; - + [appDefaults setObject:messages forKey:@"chat-history"]; } @@ -135,7 +135,7 @@ + (int)indexForContact:(NSString*)alias { NSUserDefaults* appDefaults = [NSUserDefaults standardUserDefaults]; NSArray * contacts = [appDefaults arrayForKey:@"contacts"]; - + for (int i = 0; i < [contacts count]; i++) { NSArray * contact = [contacts objectAtIndex:i]; if ([[contact objectAtIndex:0] isEqualToString:alias]) { @@ -151,14 +151,14 @@ + (int)indexForContact:(NSString*)sipUri { NSUserDefaults* appDefaults = [NSUserDefaults standardUserDefaults]; NSArray * contacts = [appDefaults arrayForKey:@"contacts"]; - + for (int i = 0; i < [contacts count]; i++) { NSArray * contact = [contacts objectAtIndex:i]; if ([[contact objectAtIndex:1] isEqualToString:sipUri]) { return i; } } - + return -1; } @@ -166,14 +166,14 @@ + (NSString*)sipUri2Alias:(NSString*)sipUri { NSUserDefaults* appDefaults = [NSUserDefaults standardUserDefaults]; NSArray * contacts = [appDefaults arrayForKey:@"contacts"]; - + for (int i = 0; i < [contacts count]; i++) { NSArray * contact = [contacts objectAtIndex:i]; if ([[contact objectAtIndex:1] isEqualToString:sipUri]) { return [contact objectAtIndex:0]; } } - + return @""; } @@ -257,7 +257,7 @@ + (int)contactCount + (NSString*) genericType:(NSString*)type forLevel:(NSNumber*)level; { NSUserDefaults* appDefaults = [NSUserDefaults standardUserDefaults]; - + if ([appDefaults dictionaryForKey:type]) { if([[appDefaults dictionaryForKey:type] objectForKey:[level stringValue]]) { return [[[appDefaults dictionaryForKey:type] objectForKey:[level stringValue]] stringValue]; @@ -271,7 +271,7 @@ + (NSString*) genericType:(NSString*)type forLevel:(NSNumber*)level; + (void)addContact:(NSArray*)contact { NSUserDefaults* appDefaults = [NSUserDefaults standardUserDefaults]; - + NSMutableArray * mutable = nil; if ([appDefaults arrayForKey:@"contacts"]) { // exists; get a mutable copy @@ -281,9 +281,9 @@ + (void)addContact:(NSArray*)contact // should never happen return; } - + [mutable addObject:contact]; - + // update user defaults [appDefaults setObject:mutable forKey:@"contacts"]; } @@ -291,7 +291,7 @@ + (void)addContact:(NSArray*)contact + (void)removeContactAtIndex:(int)index { NSUserDefaults* appDefaults = [NSUserDefaults standardUserDefaults]; - + NSMutableArray * mutable = nil; if ([appDefaults arrayForKey:@"contacts"]) { // exists; get a mutable copy @@ -301,9 +301,9 @@ + (void)removeContactAtIndex:(int)index // should never happen return; } - + [mutable removeObjectAtIndex:index]; - + // update user defaults [appDefaults setObject:mutable forKey:@"contacts"]; } @@ -311,7 +311,7 @@ + (void)removeContactAtIndex:(int)index + (void)updateContactWithSipUri:(NSString*)sipUri alias:(NSString*)alias { NSUserDefaults* appDefaults = [NSUserDefaults standardUserDefaults]; - + NSMutableArray * mutable = nil; if ([appDefaults arrayForKey:@"contacts"]) { // exists; get a mutable copy @@ -321,7 +321,7 @@ + (void)updateContactWithSipUri:(NSString*)sipUri alias:(NSString*)alias // should never happen return; } - + for (int i = 0; i < [mutable count]; i++) { NSArray * contact = [mutable objectAtIndex:i]; if ([[contact objectAtIndex:1] isEqualToString:sipUri]) { @@ -410,6 +410,7 @@ + (NSString*)convertInterappUri2RestcommUri:(NSURL*)uri * restcomm-tel://+1235@telestax.com * client://bob * restcomm-client://bob + * restcomm-app://bob -> just opens app and potentially login with user * Important note: the browser only recognizes URLs starting with 'scheme://', not 'scheme:' */ @@ -425,12 +426,14 @@ + (NSString*)convertInterappUri2RestcommUri:(NSURL*)uri NSString * normalized = [[uri absoluteString] stringByReplacingOccurrencesOfString:@"restcomm-sip" withString:@"sip"]; // also replace '://' with ':' so that the SIP stack can understand it final = [normalized stringByReplacingOccurrencesOfString:@"://" withString:@":"]; + } else if ([RCUtilities string:[uri scheme] containsString:@"app"]) { + //just open the app with no call initiated } else { // either 'tel', 'restcomm-tel', 'client' or 'restcomm-client'. Return just the host part, like 'bob' or '1235' that the Restcomm SDK can handle final = [NSString stringWithFormat:@"%@", [uri host]]; } - + NSLog(@"convertInterappUri2RestcommUri after conversion: %@", final); return final; } @@ -440,7 +443,7 @@ + (NSString*)convertInterappUri2RestcommUri:(NSURL*)uri + (void) setGenericType:(NSString*)type forLevel:(NSNumber*)level withValue:(NSNumber*)value updateType:(NSString*)updateType { NSUserDefaults* appDefaults = [NSUserDefaults standardUserDefaults]; - + NSMutableDictionary * mutable = nil; if ([appDefaults dictionaryForKey:type]) { // exists; get a mutable copy @@ -450,7 +453,7 @@ + (void) setGenericType:(NSString*)type forLevel:(NSNumber*)level withValue:(NSN // if the type does not exist create it mutable = [[NSMutableDictionary alloc] init]; } - + BOOL updateValue = YES; if (updateType && [updateType isEqualToString:@"update-when-greater"]) { // if there's a value for the level score or stars and that is bigger than the current value then don't update score @@ -458,11 +461,11 @@ + (void) setGenericType:(NSString*)type forLevel:(NSNumber*)level withValue:(NSN updateValue = NO; } } - + if (updateValue) { [mutable setObject:value forKey:[level stringValue]]; } - + // update user defaults [appDefaults setObject:mutable forKey:type]; } diff --git a/Examples/restcomm-olympus/restcomm-olympus/restcomm-olympus-Info.plist b/Examples/restcomm-olympus/restcomm-olympus/restcomm-olympus-Info.plist index c1efa25..4135b5f 100644 --- a/Examples/restcomm-olympus/restcomm-olympus/restcomm-olympus-Info.plist +++ b/Examples/restcomm-olympus/restcomm-olympus/restcomm-olympus-Info.plist @@ -26,6 +26,16 @@ ???? CFBundleURLTypes + + CFBundleTypeRole + Editor + CFBundleURLName + com.telestax.olympus.restcomm-sip + CFBundleURLSchemes + + restcomm-app + + CFBundleTypeRole Editor From 0ece33dd2583b2e5c02c8a2fde812a0622b7f8ec Mon Sep 17 00:00:00 2001 From: Antonis Tsakiridis Date: Tue, 15 Nov 2016 15:42:17 +0200 Subject: [PATCH 2/2] Fixed URL type identifier and bumped the version number --- Examples/restcomm-olympus/restcomm-olympus/Utils.m | 2 +- .../restcomm-olympus/restcomm-olympus-Info.plist | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/restcomm-olympus/restcomm-olympus/Utils.m b/Examples/restcomm-olympus/restcomm-olympus/Utils.m index 986763e..c03067e 100644 --- a/Examples/restcomm-olympus/restcomm-olympus/Utils.m +++ b/Examples/restcomm-olympus/restcomm-olympus/Utils.m @@ -427,7 +427,7 @@ + (NSString*)convertInterappUri2RestcommUri:(NSURL*)uri // also replace '://' with ':' so that the SIP stack can understand it final = [normalized stringByReplacingOccurrencesOfString:@"://" withString:@":"]; } else if ([RCUtilities string:[uri scheme] containsString:@"app"]) { - //just open the app with no call initiated + //just open the app with no call initiated } else { // either 'tel', 'restcomm-tel', 'client' or 'restcomm-client'. Return just the host part, like 'bob' or '1235' that the Restcomm SDK can handle diff --git a/Examples/restcomm-olympus/restcomm-olympus/restcomm-olympus-Info.plist b/Examples/restcomm-olympus/restcomm-olympus/restcomm-olympus-Info.plist index 4135b5f..cfbaf3c 100644 --- a/Examples/restcomm-olympus/restcomm-olympus/restcomm-olympus-Info.plist +++ b/Examples/restcomm-olympus/restcomm-olympus/restcomm-olympus-Info.plist @@ -30,7 +30,7 @@ CFBundleTypeRole Editor CFBundleURLName - com.telestax.olympus.restcomm-sip + com.telestax.olympus.restcomm-app CFBundleURLSchemes restcomm-app @@ -98,7 +98,7 @@ CFBundleVersion - BETA4.1#2 + BETA4.1#3 Fabric APIKey