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

fixes https://github.com/RestComm/restcomm-ios-sdk/issues/500 #501

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions Examples/restcomm-olympus/restcomm-olympus/Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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"];
}

Expand All @@ -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]) {
Expand All @@ -151,29 +151,29 @@ + (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;
}

+ (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 @"";
}

Expand Down Expand Up @@ -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];
Expand All @@ -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
Expand All @@ -281,17 +281,17 @@ + (void)addContact:(NSArray*)contact
// should never happen
return;
}

[mutable addObject:contact];

// update user defaults
[appDefaults setObject:mutable forKey:@"contacts"];
}

+ (void)removeContactAtIndex:(int)index
{
NSUserDefaults* appDefaults = [NSUserDefaults standardUserDefaults];

NSMutableArray * mutable = nil;
if ([appDefaults arrayForKey:@"contacts"]) {
// exists; get a mutable copy
Expand All @@ -301,17 +301,17 @@ + (void)removeContactAtIndex:(int)index
// should never happen
return;
}

[mutable removeObjectAtIndex:index];

// update user defaults
[appDefaults setObject:mutable forKey:@"contacts"];
}

+ (void)updateContactWithSipUri:(NSString*)sipUri alias:(NSString*)alias
{
NSUserDefaults* appDefaults = [NSUserDefaults standardUserDefaults];

NSMutableArray * mutable = nil;
if ([appDefaults arrayForKey:@"contacts"]) {
// exists; get a mutable copy
Expand All @@ -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]) {
Expand Down Expand Up @@ -410,6 +410,7 @@ + (NSString*)convertInterappUri2RestcommUri:(NSURL*)uri
* restcomm-tel://[email protected]
* 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:'
*/

Expand All @@ -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;
}
Expand All @@ -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
Expand All @@ -450,19 +453,19 @@ + (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
if ([mutable objectForKey:[level stringValue]] && ([value intValue] < [[mutable objectForKey:[level stringValue]] intValue])) {
updateValue = NO;
}
}

if (updateValue) {
[mutable setObject:value forKey:[level stringValue]];
}

// update user defaults
[appDefaults setObject:mutable forKey:type];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.telestax.olympus.restcomm-app</string>
<key>CFBundleURLSchemes</key>
<array>
<string>restcomm-app</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
Expand Down Expand Up @@ -88,7 +98,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>BETA4.1#2</string>
<string>BETA4.1#3</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down