From 9fcd50e031d2d970899961d6ac7afa5456c31c6a Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Wed, 15 Apr 2015 12:51:33 +0200 Subject: [PATCH 01/29] Utils.m: rename logger helper functions to LOGx instead of Linphone_x --- Classes/ContactDetailsTableViewController.m | 4 ++-- Classes/DialerViewController.m | 4 ++-- Classes/LinphoneAppDelegate.m | 24 +++++++++---------- .../LinphoneUI/UICompositeViewController.m | 4 ++-- Classes/PhoneMainView.m | 2 +- Classes/Utils/FastAddressBook.m | 2 +- Classes/Utils/Utils.h | 11 ++++----- Classes/Utils/Utils.m | 10 ++++---- 8 files changed, 30 insertions(+), 31 deletions(-) diff --git a/Classes/ContactDetailsTableViewController.m b/Classes/ContactDetailsTableViewController.m index a85bd9cad..be2b15b28 100644 --- a/Classes/ContactDetailsTableViewController.m +++ b/Classes/ContactDetailsTableViewController.m @@ -279,7 +279,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe CFTypeRef values[] = { [value copy], [LinphoneManager instance].contactSipField }; CFDictionaryRef lDict = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 2, NULL, NULL); if (entry) { - index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); + index = (int)ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); ABMultiValueReplaceValueAtIndex(lMap, lDict, index); } else { CFStringRef label = (CFStringRef)[labelArray objectAtIndex:0]; @@ -300,7 +300,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe lcMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); lMap = ABMultiValueCreateMutableCopy(lcMap); CFRelease(lcMap); - index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); + index = (int)ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); lDict = ABMultiValueCopyValueAtIndex(lMap,index); if(!CFDictionaryContainsKey(lDict, kABPersonInstantMessageServiceKey)) { /*too bad probably a gtalk number, storing uri*/ diff --git a/Classes/DialerViewController.m b/Classes/DialerViewController.m index c9480b922..4141ed3dd 100644 --- a/Classes/DialerViewController.m +++ b/Classes/DialerViewController.m @@ -289,7 +289,7 @@ static UICompositeViewDescription *compositeDescription = nil; if( attachLogs ){ char * filepath = linphone_core_compress_log_collection([LinphoneManager getLc]); if (filepath == NULL) { - Linphone_err(@"Cannot sent logs: file is NULL"); + LOGE(@"Cannot sent logs: file is NULL"); return; } NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]; @@ -300,7 +300,7 @@ static UICompositeViewDescription *compositeDescription = nil; mimeType = @"application/gzip"; filename = [appName stringByAppendingString:@".gz"]; } else { - Linphone_err(@"Unknown extension type: %@, cancelling email", filename); + LOGE(@"Unknown extension type: %@, cancelling email", filename); return; } [controller setMessageBody:NSLocalizedString(@"Application logs", nil) isHTML:NO]; diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 950bcb362..2f9c9c371 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -54,12 +54,12 @@ - (void)applicationDidEnterBackground:(UIApplication *)application{ - Linphone_log(@"%@", NSStringFromSelector(_cmd)); + LOGI(@"%@", NSStringFromSelector(_cmd)); [[LinphoneManager instance] enterBackgroundMode]; } - (void)applicationWillResignActive:(UIApplication *)application { - Linphone_log(@"%@", NSStringFromSelector(_cmd)); + LOGI(@"%@", NSStringFromSelector(_cmd)); LinphoneCore* lc = [LinphoneManager getLc]; LinphoneCall* call = linphone_core_get_current_call(lc); @@ -82,7 +82,7 @@ } - (void)applicationDidBecomeActive:(UIApplication *)application { - Linphone_log(@"%@", NSStringFromSelector(_cmd)); + LOGI(@"%@", NSStringFromSelector(_cmd)); if( startedInBackground ){ startedInBackground = FALSE; @@ -232,7 +232,7 @@ } - (void)applicationWillTerminate:(UIApplication *)application { - Linphone_log(@"%@", NSStringFromSelector(_cmd)); + LOGI(@"%@", NSStringFromSelector(_cmd)); } - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { @@ -311,7 +311,7 @@ } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { - Linphone_log(@"%@ : %@", NSStringFromSelector(_cmd), userInfo); + LOGI(@"%@ : %@", NSStringFromSelector(_cmd), userInfo); [self processRemoteNotification:userInfo]; } @@ -331,7 +331,7 @@ } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { - Linphone_log(@"%@ - state = %ld", NSStringFromSelector(_cmd), (long)application.applicationState); + LOGI(@"%@ - state = %ld", NSStringFromSelector(_cmd), (long)application.applicationState); [self fixRing]; @@ -370,7 +370,7 @@ // this method is implemented for iOS7. It is invoked when receiving a push notification for a call and it has "content-available" in the aps section. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { - Linphone_log(@"%@ : %@", NSStringFromSelector(_cmd), userInfo); + LOGI(@"%@ : %@", NSStringFromSelector(_cmd), userInfo); LinphoneManager* lm = [LinphoneManager instance]; // save the completion handler for later execution. @@ -394,23 +394,23 @@ #pragma mark - PushNotification Functions - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { - Linphone_log(@"%@ : %@", NSStringFromSelector(_cmd), deviceToken); + LOGI(@"%@ : %@", NSStringFromSelector(_cmd), deviceToken); [[LinphoneManager instance] setPushNotificationToken:deviceToken]; } - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { - Linphone_log(@"%@ : %@", NSStringFromSelector(_cmd), [error localizedDescription]); + LOGI(@"%@ : %@", NSStringFromSelector(_cmd), [error localizedDescription]); [[LinphoneManager instance] setPushNotificationToken:nil]; } #pragma mark - User notifications - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { - Linphone_log(@"%@", NSStringFromSelector(_cmd)); + LOGI(@"%@", NSStringFromSelector(_cmd)); } - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler { - Linphone_log(@"%@", NSStringFromSelector(_cmd)); + LOGI(@"%@", NSStringFromSelector(_cmd)); if( [[UIDevice currentDevice].systemVersion floatValue] >= 8){ LinphoneCore* lc = [LinphoneManager getLc]; @@ -441,7 +441,7 @@ } - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler { - Linphone_log(@"%@", NSStringFromSelector(_cmd)); + LOGI(@"%@", NSStringFromSelector(_cmd)); completionHandler(); } diff --git a/Classes/LinphoneUI/UICompositeViewController.m b/Classes/LinphoneUI/UICompositeViewController.m index f5e4126f5..0cdafc3b1 100644 --- a/Classes/LinphoneUI/UICompositeViewController.m +++ b/Classes/LinphoneUI/UICompositeViewController.m @@ -178,12 +178,12 @@ // if we start in portrait, the landscape view must get the opposite height and width if( portrait || [[UIDevice currentDevice].systemVersion floatValue] < 8 ){ - Linphone_log(@"landscape get opposite: %@", NSStringFromCGSize(oppositeFrame.size)); + LOGI(@"landscape get opposite: %@", NSStringFromCGSize(oppositeFrame.size)); [landscapeView setFrame:oppositeFrame]; } else { // if we start in landscape, the landscape view has to get the current size, // whereas the portrait has to get the opposite - Linphone_log(@"landscape get frame: %@ and portrait gets opposite: %@", NSStringFromCGSize(frame.size), NSStringFromCGSize(oppositeFrame.size)); + LOGI(@"landscape get frame: %@ and portrait gets opposite: %@", NSStringFromCGSize(frame.size), NSStringFromCGSize(oppositeFrame.size)); [landscapeView setFrame:frame]; [portraitView setFrame:oppositeFrame]; } diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index b4c070454..f7840cc9a 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -75,7 +75,7 @@ static RootViewManager* rootViewManagerInstance = nil; UIInterfaceOrientation nextViewOrientation = newMainView.interfaceOrientation; UIInterfaceOrientation previousOrientation = currentViewController.interfaceOrientation; - Linphone_log(@"Changing rootViewController: %@ -> %@", currentViewController.name, newMainView.name); + LOGI(@"Changing rootViewController: %@ -> %@", currentViewController.name, newMainView.name); currentViewController = newMainView; LinphoneAppDelegate* delegate = (LinphoneAppDelegate*)[UIApplication sharedApplication].delegate; diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index c876a277b..612b0b8c4 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -165,7 +165,7 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf if( addressBook != nil ){ NSError* err = nil; if( !ABAddressBookSave(addressBook, (CFErrorRef*)err) ){ - Linphone_warn(@"Couldn't save Address Book"); + LOGW(@"Couldn't save Address Book"); } } } diff --git a/Classes/Utils/Utils.h b/Classes/Utils/Utils.h index 28b950d5d..b4fb93b37 100644 --- a/Classes/Utils/Utils.h +++ b/Classes/Utils/Utils.h @@ -62,12 +62,11 @@ typedef enum _LinphoneLoggerSeverity { @end -void Linphone_log(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); -void Linphone_dbg(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); -void Linphone_warn(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); -void Linphone_err(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); -void Linphone_fatal(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); - +void LOGI(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); +void LOGD(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); +void LOGW(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); +void LOGE(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); +void LOGF(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); #endif diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index 31581e8cf..58a353adf 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -253,22 +253,22 @@ [LinphoneLogger logv:level format:argstart args:args]; \ va_end(args); -void Linphone_log(NSString* format, ...){ +void LOGI(NSString* format, ...){ LOGV(LinphoneLoggerLog, format); } -void Linphone_dbg(NSString* format, ...){ +void LOGD(NSString* format, ...){ LOGV(LinphoneLoggerDebug, format); } -void Linphone_warn(NSString* format, ...){ +void LOGW(NSString* format, ...){ LOGV(LinphoneLoggerWarning, format); } -void Linphone_err(NSString* format, ...){ +void LOGE(NSString* format, ...){ LOGV(LinphoneLoggerError, format); } -void Linphone_fatal(NSString* format, ...){ +void LOGF(NSString* format, ...){ LOGV(LinphoneLoggerFatal, format); } From d8dcaa19c1886f5d461786c751bfc686839d5b23 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Wed, 15 Apr 2015 12:52:46 +0200 Subject: [PATCH 02/29] xcode: update scheme as suggested by xcode --- .../xcshareddata/xcschemes/LinphoneTester.xcscheme | 8 +++++--- .../xcshareddata/xcschemes/linphone.xcscheme | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/linphone.xcodeproj/xcshareddata/xcschemes/LinphoneTester.xcscheme b/linphone.xcodeproj/xcshareddata/xcschemes/LinphoneTester.xcscheme index 8e72f5ba4..92d53560e 100644 --- a/linphone.xcodeproj/xcshareddata/xcschemes/LinphoneTester.xcscheme +++ b/linphone.xcodeproj/xcshareddata/xcschemes/LinphoneTester.xcscheme @@ -1,6 +1,6 @@ - + - + - + - + Date: Wed, 15 Apr 2015 12:53:57 +0200 Subject: [PATCH 03/29] InAppProducts: add in app feature --- Classes/InAppProductsManager.h | 27 ++++++++++++ Classes/InAppProductsManager.m | 66 ++++++++++++++++++++++++++++++ Classes/LinphoneManager.h | 3 +- Classes/LinphoneManager.m | 25 +++++------ in_app_products.plist | 7 ++++ linphone.xcodeproj/project.pbxproj | 43 +++++++++++++++---- 6 files changed, 150 insertions(+), 21 deletions(-) create mode 100644 Classes/InAppProductsManager.h create mode 100644 Classes/InAppProductsManager.m create mode 100644 in_app_products.plist diff --git a/Classes/InAppProductsManager.h b/Classes/InAppProductsManager.h new file mode 100644 index 000000000..e5a3c369e --- /dev/null +++ b/Classes/InAppProductsManager.h @@ -0,0 +1,27 @@ +/* InAppProductsManager.h + * + * Copyright (C) 2012 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import +#import + +@interface InAppProductsManager : NSObject { + NSArray *inAppProducts; +} + +@end diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m new file mode 100644 index 000000000..9bcc0a40b --- /dev/null +++ b/Classes/InAppProductsManager.m @@ -0,0 +1,66 @@ +/* InAppProductsManager.h + * + * Copyright (C) 2012 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import "InAppProductsManager.h" +#import "Utils.h" + +@implementation InAppProductsManager { + bool ready; +} + +- (instancetype)init { + if ((self = [super init]) != nil) { + [self loadProducts]; + ready = false; + } + return self; +} + +- (void)loadProducts { + if (! [SKPaymentQueue canMakePayments]) { + return; + } + + NSURL *url = [[NSBundle mainBundle] URLForResource:@"in_app_products" + withExtension:@"plist"]; + + inAppProducts = [NSArray arrayWithContentsOfURL:url]; + + SKProductsRequest *productsRequest = [[SKProductsRequest alloc] + initWithProductIdentifiers:[NSSet setWithArray:inAppProducts]]; + productsRequest.delegate = self; + [productsRequest start]; +} + +- (void)productsRequest:(SKProductsRequest *)request + didReceiveResponse:(SKProductsResponse *)response { + inAppProducts = response.products; + LOGI(@"Found %lu products purchasable", inAppProducts.count); + + for (NSString *invalidIdentifier in response.invalidProductIdentifiers) { + LOGE(@"Product Identifier with invalid ID %@", invalidIdentifier); + } + ready = true; +} + +- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { + +} + +@end \ No newline at end of file diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index daa3c4779..f2fc082c0 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -31,6 +31,7 @@ #import "IASKAppSettingsViewController.h" #import "FastAddressBook.h" #import "Utils.h" +#import "InAppProductsManager.h" #include "linphone/linphonecore.h" #include "linphone/linphone_tunnel.h" @@ -202,6 +203,6 @@ typedef struct _LinphoneManagerSounds { @property (copy) void (^silentPushCompletion)(UIBackgroundFetchResult); @property (readonly) BOOL wasRemoteProvisioned; @property (readonly) LpConfig *configDb; - +@property (readonly) InAppProductsManager *iapManager; @end diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 2f5606027..b5cd31873 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -466,7 +466,7 @@ exit_dbmigration: if( configDb == nil ) return; if( lp_config_get_int(configDb, LINPHONERC_APPLICATION_KEY, migration_flag, 0) ){ - Linphone_log(@"UserPrefs migration already performed, skip"); + LOGI(@"UserPrefs migration already performed, skip"); return; } @@ -477,11 +477,11 @@ exit_dbmigration: @"start_at_boot_preference" :@YES}; BOOL shouldSync = FALSE; - Linphone_log(@"%lu user prefs", (unsigned long)[defaults_keys count]); + LOGI(@"%lu user prefs", (unsigned long)[defaults_keys count]); for( NSString* userpref in values ){ if( [defaults_keys containsObject:userpref] ){ - Linphone_log(@"Migrating %@ from user preferences: %d", userpref, [[defaults objectForKey:userpref] boolValue]); + LOGI(@"Migrating %@ from user preferences: %d", userpref, [[defaults objectForKey:userpref] boolValue]); lp_config_set_int(configDb, LINPHONERC_APPLICATION_KEY, [userpref UTF8String], [[defaults objectForKey:userpref] boolValue]); [[NSUserDefaults standardUserDefaults] removeObjectForKey:userpref]; shouldSync = TRUE; @@ -492,7 +492,7 @@ exit_dbmigration: } if( shouldSync ){ - Linphone_log(@"Synchronizing..."); + LOGI(@"Synchronizing..."); [[NSUserDefaults standardUserDefaults] synchronize]; } // don't get back here in the future @@ -985,7 +985,7 @@ static void linphone_iphone_is_composing_received(LinphoneCore *lc, LinphoneChat + (void)kickOffNetworkConnection { static BOOL in_progress = FALSE; if( in_progress ){ - Linphone_warn(@"Connection kickoff already in progress"); + LOGW(@"Connection kickoff already in progress"); return; } in_progress = TRUE; @@ -1003,7 +1003,7 @@ static void linphone_iphone_is_composing_received(LinphoneCore *lc, LinphoneChat time_t loop_time; if( res == FALSE ){ - Linphone_log(@"Could not open write stream, backing off"); + LOGI(@"Could not open write stream, backing off"); CFRelease(writeStream); in_progress = FALSE; return; @@ -1027,10 +1027,10 @@ static void linphone_iphone_is_composing_received(LinphoneCore *lc, LinphoneChat CFWriteStreamWrite (writeStream,(const UInt8*)buff,strlen(buff)); } else if( !timeout_reached ){ CFErrorRef error = CFWriteStreamCopyError(writeStream); - Linphone_dbg(@"CFStreamError: %@", error); + LOGD(@"CFStreamError: %@", error); CFRelease(error); } else if( timeout_reached ){ - Linphone_log(@"CFStream timeout reached"); + LOGI(@"CFStream timeout reached"); } CFWriteStreamClose (writeStream); CFRelease(writeStream); @@ -1283,6 +1283,7 @@ static LinphoneCoreVTable linphonec_vtable = { [_contactSipField release]; _contactSipField = [[self lpConfigStringForKey:@"contact_im_type_value" withDefault:@"SIP"] retain]; + _iapManager = [[InAppProductsManager alloc] init]; fastAddressBook = [[FastAddressBook alloc] init]; @@ -1313,7 +1314,7 @@ static LinphoneCoreVTable linphonec_vtable = { const char* addr = linphone_proxy_config_get_addr(proxy); // we want to enable AVPF for the proxies if( addr && strstr(addr, "sip.linphone.org") != 0 ){ - Linphone_log(@"Migrating proxy config to use AVPF"); + LOGI(@"Migrating proxy config to use AVPF"); linphone_proxy_config_enable_avpf(proxy, TRUE); } proxies = proxies->next; @@ -1328,7 +1329,7 @@ static LinphoneCoreVTable linphonec_vtable = { const char* addr = linphone_proxy_config_get_addr(proxy); // we want to enable quality reporting for the proxies that are on linphone.org if( addr && strstr(addr, "sip.linphone.org") != 0 ){ - Linphone_log(@"Migrating proxy config to send quality report"); + LOGI(@"Migrating proxy config to send quality report"); linphone_proxy_config_set_quality_reporting_collector(proxy, "sip:voip-metrics@sip.linphone.org"); linphone_proxy_config_set_quality_reporting_interval(proxy, 180); linphone_proxy_config_enable_quality_reporting(proxy, TRUE); @@ -1560,7 +1561,7 @@ static int comp_call_id(const LinphoneCall* call , const char *callid) { //first, make sure this callid is not already involved in a call MSList* calls = (MSList*)linphone_core_get_calls(theLinphoneCore); if (ms_list_find_custom(calls, (MSCompareFunc)comp_call_id, [callid UTF8String])) { - Linphone_warn(@"Call id [%@] already handled",callid); + LOGW(@"Call id [%@] already handled",callid); return; }; if ([pushCallIDs count] > 10 /*max number of pending notif*/) @@ -1588,7 +1589,7 @@ static int comp_call_id(const LinphoneCall* call , const char *callid) { - (void)playMessageSound { BOOL success = [self.messagePlayer play]; if( !success ){ - Linphone_err(@"Could not play the message sound"); + LOGE(@"Could not play the message sound"); } AudioServicesPlaySystemSound([LinphoneManager instance].sounds.vibrate); } diff --git a/in_app_products.plist b/in_app_products.plist new file mode 100644 index 000000000..d269bc27a --- /dev/null +++ b/in_app_products.plist @@ -0,0 +1,7 @@ + + + + + test.tunnel + + diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index b5be344a4..dce290b01 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -122,6 +122,9 @@ 639CEB061A1DF4F1004DE38F /* UIChatRoomCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 639CEB081A1DF4F1004DE38F /* UIChatRoomCell.xib */; }; 639CEB091A1DF4FA004DE38F /* UIChatCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 639CEB0B1A1DF4FA004DE38F /* UIChatCell.xib */; }; 63CD4B4F1A5AAC8C00B84282 /* DTAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = 63CD4B4E1A5AAC8C00B84282 /* DTAlertView.m */; }; + 63E59A3A1ADE6A0100646FB3 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63E59A391ADE6A0100646FB3 /* StoreKit.framework */; }; + 63E59A3C1ADE6E5C00646FB3 /* in_app_products.plist in Resources */ = {isa = PBXBuildFile; fileRef = 63E59A3B1ADE6E5C00646FB3 /* in_app_products.plist */; }; + 63E59A3F1ADE70D900646FB3 /* InAppProductsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E59A3E1ADE70D900646FB3 /* InAppProductsManager.m */; }; 63FB30351A680E73008CA393 /* UIRoundedImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 63FB30341A680E73008CA393 /* UIRoundedImageView.m */; }; 70571E1A13FABCB000CDD3C2 /* rootca.pem in Resources */ = {isa = PBXBuildFile; fileRef = 70571E1913FABCB000CDD3C2 /* rootca.pem */; }; 7066FC0C13E830E400EFC6DC /* libvpx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7066FC0B13E830E400EFC6DC /* libvpx.a */; }; @@ -1036,6 +1039,10 @@ 639CEB0D1A1DF52C004DE38F /* ru */ = {isa = PBXFileReference; fileEncoding = 2483028224; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/UICallCell.strings; sourceTree = ""; }; 63CD4B4D1A5AAC8C00B84282 /* DTAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTAlertView.h; sourceTree = ""; }; 63CD4B4E1A5AAC8C00B84282 /* DTAlertView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTAlertView.m; sourceTree = ""; }; + 63E59A391ADE6A0100646FB3 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; + 63E59A3B1ADE6E5C00646FB3 /* in_app_products.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = in_app_products.plist; sourceTree = ""; }; + 63E59A3D1ADE6ECB00646FB3 /* InAppProductsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InAppProductsManager.h; sourceTree = ""; }; + 63E59A3E1ADE70D900646FB3 /* InAppProductsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InAppProductsManager.m; sourceTree = ""; }; 63EF7FDC1A24B5810017A416 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/AboutViewController.strings; sourceTree = ""; }; 63FB30331A680E73008CA393 /* UIRoundedImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIRoundedImageView.h; sourceTree = ""; }; 63FB30341A680E73008CA393 /* UIRoundedImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIRoundedImageView.m; sourceTree = ""; }; @@ -1893,6 +1900,7 @@ D37EE10916032DA4003608A6 /* libmediastreamer_base.a in Frameworks */, D37EE10A16032DA4003608A6 /* libmediastreamer_voip.a in Frameworks */, 226F2ED81344B0EF00F6EF27 /* libmsamr.a in Frameworks */, + 63E59A3A1ADE6A0100646FB3 /* StoreKit.framework in Frameworks */, 223148E61178A09900637D6A /* libmsilbc.a in Frameworks */, 226183B0147259670037138E /* libmssilk.a in Frameworks */, 22AA8AFE13D7125600B30535 /* libmsx264.a in Frameworks */, @@ -2035,6 +2043,8 @@ 22405EFD1601C19000B92522 /* ImageViewController.h */, 22405EFE1601C19100B92522 /* ImageViewController.m */, D37EE11016035793003608A6 /* ImageViewController.xib */, + 63E59A3D1ADE6ECB00646FB3 /* InAppProductsManager.h */, + 63E59A3E1ADE70D900646FB3 /* InAppProductsManager.m */, D31AAF5C159B3919002C6B02 /* InCallTableViewController.h */, D31AAF5D159B3919002C6B02 /* InCallTableViewController.m */, D3F83EE91582021700336684 /* InCallViewController.h */, @@ -2230,6 +2240,7 @@ F0B89C2518DC973E0050B60E /* wizard_linphone_create.rc */, F0B89C2618DC973E0050B60E /* wizard_linphone_existing.rc */, F0B89C2718DC973E0050B60E /* wizard_remote.rc */, + 63E59A3B1ADE6E5C00646FB3 /* in_app_products.plist */, ); name = Resources; sourceTree = ""; @@ -2237,6 +2248,7 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( + 63E59A391ADE6A0100646FB3 /* StoreKit.framework */, F0FF66AA1ACAEEB0008A4486 /* IOKit.framework */, F0B026F21AA710AF00FF49F7 /* libiconv.dylib */, F05BAA611A5D594E00411815 /* libz.dylib */, @@ -3184,6 +3196,11 @@ TargetAttributes = { 1D6058900D05DD3D006BFB54 = { DevelopmentTeam = Z2V957B3D6; + SystemCapabilities = { + com.apple.InAppPurchase = { + enabled = 1; + }; + }; }; F08F118319C09C6A007D70C2 = { DevelopmentTeam = Z2V957B3D6; @@ -3351,6 +3368,7 @@ D3F83F5A1582223B00336684 /* numpad_five_over.png in Resources */, D3F83F5C1582223B00336684 /* numpad_six_default.png in Resources */, 636316D91A1DECC90009B839 /* PhoneMainView.xib in Resources */, + 63E59A3C1ADE6E5C00646FB3 /* in_app_products.plist in Resources */, D3F83F5E1582223B00336684 /* numpad_six_over.png in Resources */, D3F83F601582223B00336684 /* numpad_seven_default.png in Resources */, D3F83F621582223B00336684 /* numpad_seven_over.png in Resources */, @@ -3993,6 +4011,7 @@ D37C639515AADDAF009D0BAC /* UIContactDetailsHeader.m in Sources */, D37C639B15AADEF6009D0BAC /* ContactDetailsTableViewController.m in Sources */, 636316DE1A1DEF2F0009B839 /* UIButtonShrinkable.m in Sources */, + 63E59A3F1ADE70D900646FB3 /* InAppProductsManager.m in Sources */, D3C6526715AC1A8F0092A874 /* UIEditableTableViewCell.m in Sources */, D378906515AC373B00BD776C /* ContactDetailsLabelViewController.m in Sources */, D3E8F68615ADE05B0065A226 /* UIContactDetailsFooter.m in Sources */, @@ -4515,6 +4534,7 @@ ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_WARN_UNREACHABLE_CODE = NO; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COMPRESS_PNG_FILES = NO; @@ -4533,7 +4553,8 @@ DEBUG, ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_TREAT_WARNINGS_AS_ERRORS = NO; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; HEADER_SEARCH_PATHS = ( "$(SRCROOT)/liblinphone-sdk/apple-darwin/include", "$(SRCROOT)/Classes/Utils/NinePatch/", @@ -4599,9 +4620,10 @@ ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_WARN_UNREACHABLE_CODE = NO; CODE_SIGN_ENTITLEMENTS = ""; - CODE_SIGN_IDENTITY = "iPhone Distribution"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COMPRESS_PNG_FILES = NO; COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = ""; @@ -4617,7 +4639,8 @@ HAVE_OPENH264, ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_TREAT_WARNINGS_AS_ERRORS = NO; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; HEADER_SEARCH_PATHS = ( "$(SRCROOT)/liblinphone-sdk/apple-darwin/include", "$(SRCROOT)/Classes/Utils/NinePatch/", @@ -4683,6 +4706,7 @@ ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_WARN_UNREACHABLE_CODE = NO; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COMPRESS_PNG_FILES = NO; @@ -4699,7 +4723,8 @@ HAVE_SSL, ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_TREAT_WARNINGS_AS_ERRORS = NO; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; HEADER_SEARCH_PATHS = ( "$(SRCROOT)/liblinphone-sdk/apple-darwin/include", "$(SRCROOT)/Classes/Utils/NinePatch/", @@ -4765,9 +4790,10 @@ ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_WARN_UNREACHABLE_CODE = NO; CODE_SIGN_ENTITLEMENTS = ""; - CODE_SIGN_IDENTITY = "iPhone Distribution"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COMPRESS_PNG_FILES = NO; COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = ""; @@ -4782,7 +4808,8 @@ HAVE_SSL, ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_TREAT_WARNINGS_AS_ERRORS = NO; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; HEADER_SEARCH_PATHS = ( "$(SRCROOT)/liblinphone-sdk/apple-darwin/include", "$(SRCROOT)/Classes/Utils/NinePatch/", From 1d77b5bc46cdc7ae6afaccef3b84ec029489ca83 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Wed, 15 Apr 2015 12:54:25 +0200 Subject: [PATCH 04/29] linphone-Info.plist: use linphone test ID for yet --- linphone-Info.plist | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linphone-Info.plist b/linphone-Info.plist index d7bbb99a0..6c3c7e1fa 100644 --- a/linphone-Info.plist +++ b/linphone-Info.plist @@ -11,7 +11,7 @@ CFBundleIcons~ipad CFBundleIdentifier - org.linphone.phone + org.linphone.phone.test CFBundleInfoDictionaryVersion 6.0 CFBundleLocalizations @@ -24,7 +24,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 3.7.6 + 1.0.0 CFBundleURLTypes @@ -53,7 +53,7 @@ CFBundleVersion - 2.2.6 + 1 LSRequiresIPhoneOS UIApplicationExitsOnSuspend From 0e9eafb0af762374c569e06f0af7f53ba205e4be Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Thu, 16 Apr 2015 12:29:18 +0200 Subject: [PATCH 05/29] InAppProducts: integrating UI --- Classes/Base.lproj/ChatRoomViewController.xib | 19 ++--- Classes/InAppProductsCell.h | 27 +++++++ Classes/InAppProductsCell.m | 52 ++++++++++++++ Classes/InAppProductsCell.xib | 60 ++++++++++++++++ Classes/InAppProductsManager.h | 9 ++- Classes/InAppProductsManager.m | 35 +++++++--- Classes/InAppProductsTableViewController.h | 13 ++++ Classes/InAppProductsTableViewController.m | 70 +++++++++++++++++++ Classes/InAppProductsViewController.h | 18 +++++ Classes/InAppProductsViewController.m | 70 +++++++++++++++++++ Classes/InAppProductsViewController.xib | 48 +++++++++++++ Classes/PhoneMainView.m | 5 +- Classes/SettingsViewController.m | 6 +- Settings/InAppSettings.bundle/Root.plist | 8 +++ in_app_products.plist | 7 -- linphone-Info.plist | 2 +- linphone.xcodeproj/project.pbxproj | 30 ++++++-- 17 files changed, 446 insertions(+), 33 deletions(-) create mode 100644 Classes/InAppProductsCell.h create mode 100644 Classes/InAppProductsCell.m create mode 100644 Classes/InAppProductsCell.xib create mode 100644 Classes/InAppProductsTableViewController.h create mode 100644 Classes/InAppProductsTableViewController.m create mode 100644 Classes/InAppProductsViewController.h create mode 100644 Classes/InAppProductsViewController.m create mode 100644 Classes/InAppProductsViewController.xib delete mode 100644 in_app_products.plist diff --git a/Classes/Base.lproj/ChatRoomViewController.xib b/Classes/Base.lproj/ChatRoomViewController.xib index 9e0649197..92c0c0cac 100644 --- a/Classes/Base.lproj/ChatRoomViewController.xib +++ b/Classes/Base.lproj/ChatRoomViewController.xib @@ -1,7 +1,8 @@ - + - + + @@ -248,14 +249,11 @@ + + - - - - - @@ -281,4 +279,9 @@ - \ No newline at end of file + + + + + + diff --git a/Classes/InAppProductsCell.h b/Classes/InAppProductsCell.h new file mode 100644 index 000000000..5073f93fa --- /dev/null +++ b/Classes/InAppProductsCell.h @@ -0,0 +1,27 @@ +// +// InAppProductsCell.h +// linphone +// +// Created by Gautier Pelloux-Prayer on 15/04/15. +// +// + +#import + +#import "UITransparentTVCell.h" + + +@interface InAppProductsCell : UITransparentTVCell { + +} +@property (retain, nonatomic) IBOutlet UILabel *ptitle; +@property (retain, nonatomic) IBOutlet UILabel *pdescription; +@property (retain, nonatomic) IBOutlet UILabel *pprice; +@property (retain, nonatomic) IBOutlet UISwitch *ppurchased; +@property (nonatomic) BOOL isMaximized; + +- (id)initWithIdentifier:(NSString*)identifier; + ++ (CGFloat)getHeight:(BOOL)maximized; + +@end diff --git a/Classes/InAppProductsCell.m b/Classes/InAppProductsCell.m new file mode 100644 index 000000000..e075e932b --- /dev/null +++ b/Classes/InAppProductsCell.m @@ -0,0 +1,52 @@ +// +// InAppProductsCell.m +// linphone +// +// Created by Gautier Pelloux-Prayer on 15/04/15. +// +// + +#import "InAppProductsCell.h" + +@implementation InAppProductsCell + +- (void)setIsMaximized:(BOOL)isMaximized { + _isMaximized = isMaximized; + + //show the BUY button only when not maximized + + self.frame = CGRectMake(self.frame.origin.x, + self.frame.origin.y, + self.frame.size.width, + [InAppProductsCell getHeight:isMaximized]); +} + +- (id)initWithIdentifier:(NSString*)identifier { + if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) != nil) { + NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"InAppProductsCell" + owner:self + options:nil]; + if ([arrayOfViews count] >= 1) { + [self.contentView addSubview:[arrayOfViews objectAtIndex:0]]; + } + } + return self; +} + +- (void)dealloc { + [_ptitle release]; + [_pdescription release]; + [_pprice release]; + [_ppurchased release]; + [super dealloc]; +} + +- (NSString *)description { + return [NSString stringWithFormat:@"%@ (%@): %@", _ptitle.text, _pprice.text, _pdescription.text]; +} + ++ (CGFloat)getHeight:(BOOL)maximized { + return maximized ? 120 : 44; +} + +@end diff --git a/Classes/InAppProductsCell.xib b/Classes/InAppProductsCell.xib new file mode 100644 index 000000000..ad9ca60b8 --- /dev/null +++ b/Classes/InAppProductsCell.xib @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Classes/InAppProductsManager.h b/Classes/InAppProductsManager.h index e5a3c369e..b7f35fa32 100644 --- a/Classes/InAppProductsManager.h +++ b/Classes/InAppProductsManager.h @@ -20,8 +20,15 @@ #import #import +extern NSString *const kInAppProductsReady; + @interface InAppProductsManager : NSObject { - NSArray *inAppProducts; + } +@property (readonly) NSArray *inAppProducts; + +- (void)loadProducts; +- (BOOL)isPurchased:(SKProduct*)product; + @end diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index 9bcc0a40b..66034a0c1 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -20,14 +20,16 @@ #import "InAppProductsManager.h" #import "Utils.h" +NSString *const kInAppProductsReady = @"InAppProductsReady"; + @implementation InAppProductsManager { bool ready; } - (instancetype)init { if ((self = [super init]) != nil) { - [self loadProducts]; ready = false; + [self loadProducts]; } return self; } @@ -36,31 +38,46 @@ if (! [SKPaymentQueue canMakePayments]) { return; } - - NSURL *url = [[NSBundle mainBundle] URLForResource:@"in_app_products" - withExtension:@"plist"]; - - inAppProducts = [NSArray arrayWithContentsOfURL:url]; + //TODO: move this list elsewhere + NSArray * list = [[NSArray alloc] initWithArray:@[@"test.tunnel"]]; SKProductsRequest *productsRequest = [[SKProductsRequest alloc] - initWithProductIdentifiers:[NSSet setWithArray:inAppProducts]]; + initWithProductIdentifiers:[NSSet setWithArray:list]]; productsRequest.delegate = self; [productsRequest start]; } - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { - inAppProducts = response.products; - LOGI(@"Found %lu products purchasable", inAppProducts.count); + _inAppProducts = [response.products retain]; + LOGI(@"Found %lu products purchasable", (unsigned long)_inAppProducts.count); for (NSString *invalidIdentifier in response.invalidProductIdentifiers) { LOGE(@"Product Identifier with invalid ID %@", invalidIdentifier); } ready = true; + + NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: + _inAppProducts, @"products", + nil]; + + dispatch_async(dispatch_get_main_queue(), ^(void){ + [[NSNotificationCenter defaultCenter] postNotificationName:kInAppProductsReady object:self userInfo:dict]; + }); } - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { } +- (BOOL)isPurchased:(SKProduct*)product { + for (SKProduct *prod in _inAppProducts) { + if (prod == product) { + LOGE(@"Is %@ bought? assuming NO", product.localizedTitle); + return false; //todo + } + } + return false; +} + @end \ No newline at end of file diff --git a/Classes/InAppProductsTableViewController.h b/Classes/InAppProductsTableViewController.h new file mode 100644 index 000000000..a98352c37 --- /dev/null +++ b/Classes/InAppProductsTableViewController.h @@ -0,0 +1,13 @@ +// +// InAppProductsTableViewController.h +// linphone +// +// Created by Gautier Pelloux-Prayer on 16/04/15. +// +// + +#import + +@interface InAppProductsTableViewController : UITableViewController + +@end diff --git a/Classes/InAppProductsTableViewController.m b/Classes/InAppProductsTableViewController.m new file mode 100644 index 000000000..fa86d45b6 --- /dev/null +++ b/Classes/InAppProductsTableViewController.m @@ -0,0 +1,70 @@ +// +// InAppProductsTableViewController.m +// linphone +// +// Created by Gautier Pelloux-Prayer on 16/04/15. +// +// + +#import "InAppProductsTableViewController.h" +#import "InAppProductsCell.h" +#import "InAppProductsManager.h" +#import "LinphoneManager.h" + +@implementation InAppProductsTableViewController { + InAppProductsManager *iapm; + NSInteger currentExpanded; +} + +- (void)viewWillAppear:(BOOL)animated { + iapm = [[LinphoneManager instance] iapManager]; + + [iapm loadProducts]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return [iapm inAppProducts].count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *kCellId = @"InAppProductsCell"; + InAppProductsCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; + if (cell == nil) { + cell = [[[InAppProductsCell alloc] initWithIdentifier:kCellId] autorelease]; + } + SKProduct *prod = [[[[LinphoneManager instance] iapManager] inAppProducts] objectAtIndex:indexPath.row]; + [cell.ptitle setText: [prod localizedTitle]]; + [cell.pdescription setText: [prod localizedDescription]]; + [cell.pprice setText: [NSString stringWithFormat:@"%@", [prod price]]]; + [cell.ppurchased setEnabled: [iapm isPurchased:prod]]; + cell.isMaximized = (currentExpanded == indexPath.row); + + LOGI(@"One more: %@", cell); + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + if(currentExpanded == indexPath.row) { + currentExpanded = -1; + [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; + return; + } else if(currentExpanded >= 0) { + NSIndexPath *previousPath = [NSIndexPath indexPathForRow:currentExpanded inSection:0]; + currentExpanded = indexPath.row; + [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade]; + } + currentExpanded = indexPath.row; + [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; +} + +-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + return [InAppProductsCell getHeight:(currentExpanded == indexPath.row)]; +} + +@end diff --git a/Classes/InAppProductsViewController.h b/Classes/InAppProductsViewController.h new file mode 100644 index 000000000..632240657 --- /dev/null +++ b/Classes/InAppProductsViewController.h @@ -0,0 +1,18 @@ +// +// InAppProductsViewController.h +// linphone +// +// Created by Gautier Pelloux-Prayer on 15/04/15. +// +// + +#import +#import "UICompositeViewController.h" +#import "InAppProductsTableViewController.h" + +@interface InAppProductsViewController : UIViewController { +} + +@property (nonatomic, retain) IBOutlet InAppProductsTableViewController* tableController; + +@end diff --git a/Classes/InAppProductsViewController.m b/Classes/InAppProductsViewController.m new file mode 100644 index 000000000..67dab35cd --- /dev/null +++ b/Classes/InAppProductsViewController.m @@ -0,0 +1,70 @@ +// +// InAppProductsViewController.m +// linphone +// +// Created by Gautier Pelloux-Prayer on 15/04/15. +// +// + +#import "InAppProductsViewController.h" +#import "InAppProductsCell.h" + +@implementation InAppProductsViewController + +#pragma mark - Lifecycle Functions + +- (id)init { + return [super initWithNibName:@"InAppProductsViewController" bundle:[NSBundle mainBundle]]; +} + + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + + [_tableController release]; + + [super dealloc]; +} + +#pragma mark - ViewController Functions + +- (void)viewDidLoad { + [super viewDidLoad]; +} + +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; +// [[NSNotificationCenter defaultCenter] addObserver:self +// selector:@selector(textReceivedEvent:) +// name:kLinphoneTextReceived +// object:nil]; +} + +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + +// [[NSNotificationCenter defaultCenter] removeObserver:self +// name:kLinphoneTextReceived +// object:nil]; +} + +#pragma mark - UICompositeViewDelegate Functions + +static UICompositeViewDescription *compositeDescription = nil; + ++ (UICompositeViewDescription *)compositeViewDescription { + if(compositeDescription == nil) { + compositeDescription = [[UICompositeViewDescription alloc] init:@"InAppProducts" + content:@"InAppProductsViewController" + stateBar:nil + stateBarEnabled:false + tabBar: @"UIMainBar" + tabBarEnabled:true + fullscreen:false + landscapeMode:[LinphoneManager runningOnIpad] + portraitMode:true]; + } + return compositeDescription; +} + +@end \ No newline at end of file diff --git a/Classes/InAppProductsViewController.xib b/Classes/InAppProductsViewController.xib new file mode 100644 index 000000000..3d871c635 --- /dev/null +++ b/Classes/InAppProductsViewController.xib @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index f7840cc9a..e1ad68ec9 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -20,6 +20,7 @@ #import #import +#import "InAppProductsViewController.h" #import "LinphoneAppDelegate.h" #import "PhoneMainView.h" #import "Utils.h" @@ -403,7 +404,6 @@ static RootViewManager* rootViewManagerInstance = nil; } } } - - (void)startUp { LinphoneCore* core = nil; @try { @@ -419,7 +419,8 @@ static RootViewManager* rootViewManagerInstance = nil; // Change to default view const MSList *list = linphone_core_get_proxy_config_list(core); if(list != NULL || ([lm lpConfigBoolForKey:@"hide_wizard_preference"] == true) || lm.isTesting) { - [self changeCurrentView: [DialerViewController compositeViewDescription]]; + [self changeCurrentView: [InAppProductsViewController compositeViewDescription]]; + } else { WizardViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[WizardViewController compositeViewDescription]], WizardViewController); if(controller != nil) { diff --git a/Classes/SettingsViewController.m b/Classes/SettingsViewController.m index 909a8fb39..d200f59e3 100644 --- a/Classes/SettingsViewController.m +++ b/Classes/SettingsViewController.m @@ -22,6 +22,7 @@ #import "PhoneMainView.h" #import "UILinphone.h" #import "UACellBackgroundView.h" +#import "InAppProductsViewController.h" #import "DCRoundSwitch.h" @@ -466,6 +467,7 @@ static UICompositeViewDescription *compositeDescription = nil; selector:@selector(appSettingChanged:) name:kIASKAppSettingChanged object:nil]; + } @@ -603,7 +605,7 @@ static UICompositeViewDescription *compositeDescription = nil; [hiddenKeys addObject:@"send_logs_button"]; [hiddenKeys addObject:@"reset_logs_button"]; } - + [hiddenKeys addObject:@"playback_gain_preference"]; [hiddenKeys addObject:@"microphone_gain_preference"]; @@ -770,6 +772,8 @@ static UICompositeViewDescription *compositeDescription = nil; } [self emailAttachment:[NSData dataWithContentsOfFile:[NSString stringWithUTF8String:filepath]] mimeType:mimeType name:filename]; ms_free(filepath); + } else if([key isEqual:@"in_app_products_button"]) { + [[PhoneMainView instance] changeCurrentView:[InAppProductsViewController compositeViewDescription] push:TRUE]; } } diff --git a/Settings/InAppSettings.bundle/Root.plist b/Settings/InAppSettings.bundle/Root.plist index 62dbcc5ec..87206bbc6 100644 --- a/Settings/InAppSettings.bundle/Root.plist +++ b/Settings/InAppSettings.bundle/Root.plist @@ -242,6 +242,14 @@ Type PSChildPaneSpecifier + + Key + in_app_products_button + Title + Extra features + Type + IASKButtonSpecifier + Title diff --git a/in_app_products.plist b/in_app_products.plist deleted file mode 100644 index d269bc27a..000000000 --- a/in_app_products.plist +++ /dev/null @@ -1,7 +0,0 @@ - - - - - test.tunnel - - diff --git a/linphone-Info.plist b/linphone-Info.plist index 6c3c7e1fa..1fd8768b6 100644 --- a/linphone-Info.plist +++ b/linphone-Info.plist @@ -5,7 +5,7 @@ CFBundleDevelopmentRegion English CFBundleDisplayName - Linphone + LinphoneTest CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIcons~ipad diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index dce290b01..12f7f743a 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -112,6 +112,11 @@ 57F005CA15EE2D9200914747 /* linphonerc-factory~ipad in Resources */ = {isa = PBXBuildFile; fileRef = 57F005C715EE2D9200914747 /* linphonerc-factory~ipad */; }; 631C4FB119D2A8F2004BFE77 /* UIDigitButtonLongPlus.m in Sources */ = {isa = PBXBuildFile; fileRef = 631C4FB019D2A8F2004BFE77 /* UIDigitButtonLongPlus.m */; }; 631C4FB719D2C3A6004BFE77 /* UIDigitButtonLongVoiceMail.m in Sources */ = {isa = PBXBuildFile; fileRef = 631C4FB619D2C3A6004BFE77 /* UIDigitButtonLongVoiceMail.m */; }; + 6359DE7F1ADEB54200EA15C0 /* InAppProductsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6359DE7D1ADEB54200EA15C0 /* InAppProductsViewController.m */; }; + 6359DE801ADEB54200EA15C0 /* InAppProductsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6359DE7E1ADEB54200EA15C0 /* InAppProductsViewController.xib */; }; + 6359DE841ADEB64100EA15C0 /* InAppProductsCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6359DE821ADEB64100EA15C0 /* InAppProductsCell.m */; }; + 6359DE851ADEB64100EA15C0 /* InAppProductsCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6359DE831ADEB64100EA15C0 /* InAppProductsCell.xib */; }; + 6359DE8B1ADF9EB900EA15C0 /* InAppProductsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6359DE8A1ADF9EB900EA15C0 /* InAppProductsTableViewController.m */; }; 636316D11A1DEBCB0009B839 /* AboutViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 636316D31A1DEBCB0009B839 /* AboutViewController.xib */; }; 636316D41A1DEC650009B839 /* SettingsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 636316D61A1DEC650009B839 /* SettingsViewController.xib */; }; 636316D91A1DECC90009B839 /* PhoneMainView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 636316D71A1DECC90009B839 /* PhoneMainView.xib */; }; @@ -123,7 +128,6 @@ 639CEB091A1DF4FA004DE38F /* UIChatCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 639CEB0B1A1DF4FA004DE38F /* UIChatCell.xib */; }; 63CD4B4F1A5AAC8C00B84282 /* DTAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = 63CD4B4E1A5AAC8C00B84282 /* DTAlertView.m */; }; 63E59A3A1ADE6A0100646FB3 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63E59A391ADE6A0100646FB3 /* StoreKit.framework */; }; - 63E59A3C1ADE6E5C00646FB3 /* in_app_products.plist in Resources */ = {isa = PBXBuildFile; fileRef = 63E59A3B1ADE6E5C00646FB3 /* in_app_products.plist */; }; 63E59A3F1ADE70D900646FB3 /* InAppProductsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E59A3E1ADE70D900646FB3 /* InAppProductsManager.m */; }; 63FB30351A680E73008CA393 /* UIRoundedImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 63FB30341A680E73008CA393 /* UIRoundedImageView.m */; }; 70571E1A13FABCB000CDD3C2 /* rootca.pem in Resources */ = {isa = PBXBuildFile; fileRef = 70571E1913FABCB000CDD3C2 /* rootca.pem */; }; @@ -1023,6 +1027,14 @@ 631C4FB519D2C3A6004BFE77 /* UIDigitButtonLongVoiceMail.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIDigitButtonLongVoiceMail.h; sourceTree = ""; }; 631C4FB619D2C3A6004BFE77 /* UIDigitButtonLongVoiceMail.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIDigitButtonLongVoiceMail.m; sourceTree = ""; }; 633E388219FFB0F400936D1C /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; + 6359DE7C1ADEB54200EA15C0 /* InAppProductsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InAppProductsViewController.h; sourceTree = ""; }; + 6359DE7D1ADEB54200EA15C0 /* InAppProductsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InAppProductsViewController.m; sourceTree = ""; }; + 6359DE7E1ADEB54200EA15C0 /* InAppProductsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = InAppProductsViewController.xib; sourceTree = ""; }; + 6359DE811ADEB64100EA15C0 /* InAppProductsCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InAppProductsCell.h; sourceTree = ""; }; + 6359DE821ADEB64100EA15C0 /* InAppProductsCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InAppProductsCell.m; sourceTree = ""; }; + 6359DE831ADEB64100EA15C0 /* InAppProductsCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = InAppProductsCell.xib; sourceTree = ""; }; + 6359DE891ADF9EB900EA15C0 /* InAppProductsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InAppProductsTableViewController.h; sourceTree = ""; }; + 6359DE8A1ADF9EB900EA15C0 /* InAppProductsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InAppProductsTableViewController.m; sourceTree = ""; }; 636316D21A1DEBCB0009B839 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/AboutViewController.xib; sourceTree = ""; }; 636316D51A1DEC650009B839 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/SettingsViewController.xib; sourceTree = ""; }; 636316D81A1DECC90009B839 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PhoneMainView.xib; sourceTree = ""; }; @@ -1040,7 +1052,6 @@ 63CD4B4D1A5AAC8C00B84282 /* DTAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTAlertView.h; sourceTree = ""; }; 63CD4B4E1A5AAC8C00B84282 /* DTAlertView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTAlertView.m; sourceTree = ""; }; 63E59A391ADE6A0100646FB3 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; - 63E59A3B1ADE6E5C00646FB3 /* in_app_products.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = in_app_products.plist; sourceTree = ""; }; 63E59A3D1ADE6ECB00646FB3 /* InAppProductsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InAppProductsManager.h; sourceTree = ""; }; 63E59A3E1ADE70D900646FB3 /* InAppProductsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InAppProductsManager.m; sourceTree = ""; }; 63EF7FDC1A24B5810017A416 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/AboutViewController.strings; sourceTree = ""; }; @@ -2043,8 +2054,16 @@ 22405EFD1601C19000B92522 /* ImageViewController.h */, 22405EFE1601C19100B92522 /* ImageViewController.m */, D37EE11016035793003608A6 /* ImageViewController.xib */, + 6359DE811ADEB64100EA15C0 /* InAppProductsCell.h */, + 6359DE821ADEB64100EA15C0 /* InAppProductsCell.m */, + 6359DE831ADEB64100EA15C0 /* InAppProductsCell.xib */, 63E59A3D1ADE6ECB00646FB3 /* InAppProductsManager.h */, 63E59A3E1ADE70D900646FB3 /* InAppProductsManager.m */, + 6359DE891ADF9EB900EA15C0 /* InAppProductsTableViewController.h */, + 6359DE8A1ADF9EB900EA15C0 /* InAppProductsTableViewController.m */, + 6359DE7C1ADEB54200EA15C0 /* InAppProductsViewController.h */, + 6359DE7D1ADEB54200EA15C0 /* InAppProductsViewController.m */, + 6359DE7E1ADEB54200EA15C0 /* InAppProductsViewController.xib */, D31AAF5C159B3919002C6B02 /* InCallTableViewController.h */, D31AAF5D159B3919002C6B02 /* InCallTableViewController.m */, D3F83EE91582021700336684 /* InCallViewController.h */, @@ -2240,7 +2259,6 @@ F0B89C2518DC973E0050B60E /* wizard_linphone_create.rc */, F0B89C2618DC973E0050B60E /* wizard_linphone_existing.rc */, F0B89C2718DC973E0050B60E /* wizard_remote.rc */, - 63E59A3B1ADE6E5C00646FB3 /* in_app_products.plist */, ); name = Resources; sourceTree = ""; @@ -3331,6 +3349,7 @@ D38327F71580FE3A00FA0D23 /* settings_default.png in Resources */, D38327F81580FE3A00FA0D23 /* settings_selected.png in Resources */, D38327F91580FE3A00FA0D23 /* chat_default.png in Resources */, + 6359DE801ADEB54200EA15C0 /* InAppProductsViewController.xib in Resources */, D38327FA1580FE3A00FA0D23 /* chat_selected.png in Resources */, D3832800158100E400FA0D23 /* contacts_over.png in Resources */, D3832801158100E400FA0D23 /* history_over.png in Resources */, @@ -3367,8 +3386,8 @@ D3F83F581582223B00336684 /* numpad_five_default.png in Resources */, D3F83F5A1582223B00336684 /* numpad_five_over.png in Resources */, D3F83F5C1582223B00336684 /* numpad_six_default.png in Resources */, + 6359DE851ADEB64100EA15C0 /* InAppProductsCell.xib in Resources */, 636316D91A1DECC90009B839 /* PhoneMainView.xib in Resources */, - 63E59A3C1ADE6E5C00646FB3 /* in_app_products.plist in Resources */, D3F83F5E1582223B00336684 /* numpad_six_over.png in Resources */, D3F83F601582223B00336684 /* numpad_seven_default.png in Resources */, D3F83F621582223B00336684 /* numpad_seven_over.png in Resources */, @@ -4039,10 +4058,13 @@ D3807FFC15C2894A005BE9BC /* IASKPSTitleValueSpecifierViewCell.m in Sources */, D3807FFE15C2894A005BE9BC /* IASKSlider.m in Sources */, D380800015C2894A005BE9BC /* IASKSwitch.m in Sources */, + 6359DE8B1ADF9EB900EA15C0 /* InAppProductsTableViewController.m in Sources */, D380800215C2894A005BE9BC /* IASKTextField.m in Sources */, D380800515C28A7A005BE9BC /* UILinphone.m in Sources */, D380801315C299D0005BE9BC /* ColorSpaceUtilites.m in Sources */, + 6359DE7F1ADEB54200EA15C0 /* InAppProductsViewController.m in Sources */, D378AB2A15DCDB4A0098505D /* ImagePickerViewController.m in Sources */, + 6359DE841ADEB64100EA15C0 /* InAppProductsCell.m in Sources */, 22405F001601C19200B92522 /* ImageViewController.m in Sources */, D3ED40191602172200BF332B /* HPGrowingTextView.m in Sources */, D3ED401B1602172200BF332B /* HPTextViewInternal.m in Sources */, From 182e39f66d0e7e1ab47e874ec34551037f0a229f Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Thu, 16 Apr 2015 14:38:31 +0200 Subject: [PATCH 06/29] Continue --- Classes/InAppProductsCell.h | 8 ++-- Classes/InAppProductsCell.m | 9 +++-- Classes/InAppProductsCell.xib | 26 ++++++------- Classes/InAppProductsManager.h | 2 +- Classes/InAppProductsManager.m | 4 ++ Classes/InAppProductsTableViewController.m | 44 +++++++++++++++------- Classes/InAppProductsViewController.xib | 4 +- 7 files changed, 58 insertions(+), 39 deletions(-) diff --git a/Classes/InAppProductsCell.h b/Classes/InAppProductsCell.h index 5073f93fa..871c090f5 100644 --- a/Classes/InAppProductsCell.h +++ b/Classes/InAppProductsCell.h @@ -8,19 +8,17 @@ #import -#import "UITransparentTVCell.h" - - -@interface InAppProductsCell : UITransparentTVCell { +@interface InAppProductsCell : UITableViewCell { } @property (retain, nonatomic) IBOutlet UILabel *ptitle; @property (retain, nonatomic) IBOutlet UILabel *pdescription; @property (retain, nonatomic) IBOutlet UILabel *pprice; @property (retain, nonatomic) IBOutlet UISwitch *ppurchased; @property (nonatomic) BOOL isMaximized; +@property (retain, nonatomic) NSString *productID; -- (id)initWithIdentifier:(NSString*)identifier; +- (id)initWithIdentifier:(NSString*)identifier maximized:(bool)maximized; + (CGFloat)getHeight:(BOOL)maximized; diff --git a/Classes/InAppProductsCell.m b/Classes/InAppProductsCell.m index e075e932b..fe9edc42d 100644 --- a/Classes/InAppProductsCell.m +++ b/Classes/InAppProductsCell.m @@ -7,6 +7,7 @@ // #import "InAppProductsCell.h" +#import "LinphoneManager.h" @implementation InAppProductsCell @@ -14,6 +15,7 @@ _isMaximized = isMaximized; //show the BUY button only when not maximized +// _buyButton.hidden = !isMaximized; self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, @@ -21,7 +23,7 @@ [InAppProductsCell getHeight:isMaximized]); } -- (id)initWithIdentifier:(NSString*)identifier { +- (id)initWithIdentifier:(NSString*)identifier maximized:(bool)maximized { if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) != nil) { NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"InAppProductsCell" owner:self @@ -29,6 +31,7 @@ if ([arrayOfViews count] >= 1) { [self.contentView addSubview:[arrayOfViews objectAtIndex:0]]; } + _isMaximized = maximized; } return self; } @@ -42,11 +45,11 @@ } - (NSString *)description { - return [NSString stringWithFormat:@"%@ (%@): %@", _ptitle.text, _pprice.text, _pdescription.text]; + return [NSString stringWithFormat:@"%@ (%@): %@ (%@)", _ptitle.text, _pprice.text, _pdescription.text, _isMaximized ? @"maximized":@"minimized"]; } + (CGFloat)getHeight:(BOOL)maximized { - return maximized ? 120 : 44; + return maximized ? 40 : 40; } @end diff --git a/Classes/InAppProductsCell.xib b/Classes/InAppProductsCell.xib index ad9ca60b8..135e74bb1 100644 --- a/Classes/InAppProductsCell.xib +++ b/Classes/InAppProductsCell.xib @@ -1,7 +1,8 @@ - + + @@ -14,42 +15,39 @@ - - - + + + - - - - - + diff --git a/Classes/InAppProductsManager.h b/Classes/InAppProductsManager.h index b7f35fa32..03927caf1 100644 --- a/Classes/InAppProductsManager.h +++ b/Classes/InAppProductsManager.h @@ -30,5 +30,5 @@ extern NSString *const kInAppProductsReady; - (void)loadProducts; - (BOOL)isPurchased:(SKProduct*)product; - +- (void)purchaseWithID:(NSString*)productId; @end diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index 66034a0c1..3a0faa3a3 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -80,4 +80,8 @@ NSString *const kInAppProductsReady = @"InAppProductsReady"; return false; } +- (void)purchaseWithID:(NSString *)productId { + +} + @end \ No newline at end of file diff --git a/Classes/InAppProductsTableViewController.m b/Classes/InAppProductsTableViewController.m index fa86d45b6..0101ab94f 100644 --- a/Classes/InAppProductsTableViewController.m +++ b/Classes/InAppProductsTableViewController.m @@ -10,6 +10,7 @@ #import "InAppProductsCell.h" #import "InAppProductsManager.h" #import "LinphoneManager.h" +#import "DTAlertView.h" @implementation InAppProductsTableViewController { InAppProductsManager *iapm; @@ -18,7 +19,7 @@ - (void)viewWillAppear:(BOOL)animated { iapm = [[LinphoneManager instance] iapManager]; - + currentExpanded = -1; [iapm loadProducts]; } @@ -36,31 +37,46 @@ static NSString *kCellId = @"InAppProductsCell"; InAppProductsCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; if (cell == nil) { - cell = [[[InAppProductsCell alloc] initWithIdentifier:kCellId] autorelease]; + cell = [[[InAppProductsCell alloc] initWithIdentifier:kCellId maximized:(currentExpanded == indexPath.row)] autorelease]; } SKProduct *prod = [[[[LinphoneManager instance] iapManager] inAppProducts] objectAtIndex:indexPath.row]; [cell.ptitle setText: [prod localizedTitle]]; [cell.pdescription setText: [prod localizedDescription]]; [cell.pprice setText: [NSString stringWithFormat:@"%@", [prod price]]]; - [cell.ppurchased setEnabled: [iapm isPurchased:prod]]; + [cell.ppurchased setOn: [iapm isPurchased:prod]]; cell.isMaximized = (currentExpanded == indexPath.row); - + cell.productID = prod.productIdentifier; + LOGI(@"One more: %@", cell); return cell; } +//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { +// if(currentExpanded == indexPath.row) { +// currentExpanded = -1; +// [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; +// return; +// } else if(currentExpanded >= 0) { +// NSIndexPath *previousPath = [NSIndexPath indexPathForRow:currentExpanded inSection:0]; +// currentExpanded = indexPath.row; +// [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade]; +// } +// currentExpanded = indexPath.row; +// [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; +//} + - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - if(currentExpanded == indexPath.row) { - currentExpanded = -1; - [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; - return; - } else if(currentExpanded >= 0) { - NSIndexPath *previousPath = [NSIndexPath indexPathForRow:currentExpanded inSection:0]; - currentExpanded = indexPath.row; - [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade]; + InAppProductsCell *cell = (InAppProductsCell*)[tableView cellForRowAtIndexPath:indexPath]; + if (cell.ppurchased.isOn) { + DTAlertView* alert = [[DTAlertView alloc] initWithTitle:NSLocalizedString(@"Already purchased", nil) message: [NSString stringWithFormat:NSLocalizedString(@"You already bought %@.",nil), cell.ptitle.text]]; + + [alert addCancelButtonWithTitle:NSLocalizedString(@"OK", nil) block:nil]; + [alert show]; + [alert release]; + } else { + //try to purchase item, and if successfull change the switch + [[[LinphoneManager instance] iapManager] purchaseWithID: cell.productID]; } - currentExpanded = indexPath.row; - [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/Classes/InAppProductsViewController.xib b/Classes/InAppProductsViewController.xib index 3d871c635..d6893f211 100644 --- a/Classes/InAppProductsViewController.xib +++ b/Classes/InAppProductsViewController.xib @@ -16,10 +16,10 @@ - + - + From 35c5adf02a813dcf5bfdeb229ef7f649f6e5fde2 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 17 Apr 2015 10:50:54 +0200 Subject: [PATCH 07/29] Utils.m: simplify logging helper functions --- Classes/Utils/Utils.h | 34 ++++++++-------- Classes/Utils/Utils.m | 91 +++++++++++++------------------------------ 2 files changed, 45 insertions(+), 80 deletions(-) diff --git a/Classes/Utils/Utils.h b/Classes/Utils/Utils.h index b4fb93b37..0edac128a 100644 --- a/Classes/Utils/Utils.h +++ b/Classes/Utils/Utils.h @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #ifndef LINPHONE_UTILS_H #define LINPHONE_UTILS_H @@ -62,11 +62,11 @@ typedef enum _LinphoneLoggerSeverity { @end -void LOGI(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); -void LOGD(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); -void LOGW(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); -void LOGE(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); -void LOGF(NSString* format, ...) NS_FORMAT_FUNCTION(1,2); - +#define LOGV(level, ...) [LinphoneLogger log:level format:__VA_ARGS__] +#define LOGI(...) LOGV(LinphoneLoggerLog, __VA_ARGS__) +#define LOGD(...) LOGV(LinphoneLoggerDebug, __VA_ARGS__) +#define LOGW(...) LOGV(LinphoneLoggerWarning, __VA_ARGS__) +#define LOGE(...) LOGV(LinphoneLoggerError, __VA_ARGS__) +#define LOGF(...) LOGV(LinphoneLoggerFatal, __VA_ARGS__) #endif diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index 58a353adf..8cdde9661 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "Utils.h" @@ -25,18 +25,8 @@ + (void)logv:(LinphoneLoggerSeverity)severity format:(NSString*)format args:(va_list)args{ - NSString *str = [[NSString alloc] initWithFormat: format arguments:args]; - if(severity <= LinphoneLoggerDebug) { - ms_debug("%s", [str UTF8String]); - } else if(severity <= LinphoneLoggerLog) { - ms_message("%s", [str UTF8String]); - } else if(severity <= LinphoneLoggerWarning) { - ms_warning("%s", [str UTF8String]); - } else if(severity <= LinphoneLoggerError) { - ms_error("%s", [str UTF8String]); - } else if(severity <= LinphoneLoggerFatal) { - ms_fatal("%s", [str UTF8String]); - } + NSString *str = [[NSString alloc] initWithFormat:format arguments:args]; + [self logc:severity format:[str UTF8String]]; [str release]; } @@ -104,15 +94,15 @@ // Set selected+over title: IB lack ! [button setTitle:[button titleForState:UIControlStateSelected] forState:(UIControlStateHighlighted | UIControlStateSelected)]; - + // Set selected+over titleColor: IB lack ! [button setTitleColor:[button titleColorForState:UIControlStateHighlighted] forState:(UIControlStateHighlighted | UIControlStateSelected)]; - + // Set selected+disabled title: IB lack ! [button setTitle:[button titleForState:UIControlStateSelected] forState:(UIControlStateDisabled | UIControlStateSelected)]; - + // Set selected+disabled titleColor: IB lack ! [button setTitleColor:[button titleColorForState:UIControlStateDisabled] forState:(UIControlStateDisabled | UIControlStateSelected)]; @@ -122,15 +112,15 @@ // Set selected+over title: IB lack ! [button setTitle:[button titleForState:UIControlStateSelected] forState:(UIControlStateHighlighted | UIControlStateSelected)]; - + // Set selected+over titleColor: IB lack ! [button setTitleColor:[button titleColorForState:UIControlStateSelected] forState:(UIControlStateHighlighted | UIControlStateSelected)]; - + // Set selected+disabled title: IB lack ! [button setTitle:[button titleForState:UIControlStateSelected] forState:(UIControlStateDisabled | UIControlStateSelected)]; - + // Set selected+disabled titleColor: IB lack ! [button setTitleColor:[button titleColorForState:UIControlStateDisabled] forState:(UIControlStateDisabled | UIControlStateSelected)]; @@ -144,7 +134,7 @@ [LinphoneUtils addDictEntry:attributes item:[button titleForState:UIControlStateDisabled | UIControlStateHighlighted] key:@"title-disabled-highlighted"]; [LinphoneUtils addDictEntry:attributes item:[button titleForState:UIControlStateSelected | UIControlStateHighlighted] key:@"title-selected-highlighted"]; [LinphoneUtils addDictEntry:attributes item:[button titleForState:UIControlStateSelected | UIControlStateDisabled] key:@"title-selected-disabled"]; - + [LinphoneUtils addDictEntry:attributes item:[button titleColorForState:UIControlStateNormal] key:@"title-color-normal"]; [LinphoneUtils addDictEntry:attributes item:[button titleColorForState:UIControlStateHighlighted] key:@"title-color-highlighted"]; [LinphoneUtils addDictEntry:attributes item:[button titleColorForState:UIControlStateDisabled] key:@"title-color-disabled"]; @@ -152,11 +142,11 @@ [LinphoneUtils addDictEntry:attributes item:[button titleColorForState:UIControlStateDisabled | UIControlStateHighlighted] key:@"title-color-disabled-highlighted"]; [LinphoneUtils addDictEntry:attributes item:[button titleColorForState:UIControlStateSelected | UIControlStateHighlighted] key:@"title-color-selected-highlighted"]; [LinphoneUtils addDictEntry:attributes item:[button titleColorForState:UIControlStateSelected | UIControlStateDisabled] key:@"title-color-selected-disabled"]; - + [LinphoneUtils addDictEntry:attributes item:NSStringFromUIEdgeInsets([button titleEdgeInsets]) key:@"title-edge"]; [LinphoneUtils addDictEntry:attributes item:NSStringFromUIEdgeInsets([button contentEdgeInsets]) key:@"content-edge"]; [LinphoneUtils addDictEntry:attributes item:NSStringFromUIEdgeInsets([button imageEdgeInsets]) key:@"image-edge"]; - + [LinphoneUtils addDictEntry:attributes item:[button imageForState:UIControlStateNormal] key:@"image-normal"]; [LinphoneUtils addDictEntry:attributes item:[button imageForState:UIControlStateHighlighted] key:@"image-highlighted"]; [LinphoneUtils addDictEntry:attributes item:[button imageForState:UIControlStateDisabled] key:@"image-disabled"]; @@ -164,7 +154,7 @@ [LinphoneUtils addDictEntry:attributes item:[button imageForState:UIControlStateDisabled | UIControlStateHighlighted] key:@"image-disabled-highlighted"]; [LinphoneUtils addDictEntry:attributes item:[button imageForState:UIControlStateSelected | UIControlStateHighlighted] key:@"image-selected-highlighted"]; [LinphoneUtils addDictEntry:attributes item:[button imageForState:UIControlStateSelected | UIControlStateDisabled] key:@"image-selected-disabled"]; - + [LinphoneUtils addDictEntry:attributes item:[button backgroundImageForState:UIControlStateNormal] key:@"background-normal"]; [LinphoneUtils addDictEntry:attributes item:[button backgroundImageForState:UIControlStateHighlighted] key:@"background-highlighted"]; [LinphoneUtils addDictEntry:attributes item:[button backgroundImageForState:UIControlStateDisabled] key:@"background-disabled"]; @@ -182,7 +172,7 @@ [button setTitle:[LinphoneUtils getDictEntry:attributes key:@"title-disabled-highlighted"] forState:UIControlStateDisabled | UIControlStateHighlighted]; [button setTitle:[LinphoneUtils getDictEntry:attributes key:@"title-selected-highlighted"] forState:UIControlStateSelected | UIControlStateHighlighted]; [button setTitle:[LinphoneUtils getDictEntry:attributes key:@"title-selected-disabled"] forState:UIControlStateSelected | UIControlStateDisabled]; - + [button setTitleColor:[LinphoneUtils getDictEntry:attributes key:@"title-color-normal"] forState:UIControlStateNormal]; [button setTitleColor:[LinphoneUtils getDictEntry:attributes key:@"title-color-highlighted"] forState:UIControlStateHighlighted]; [button setTitleColor:[LinphoneUtils getDictEntry:attributes key:@"title-color-disabled"] forState:UIControlStateDisabled]; @@ -190,7 +180,7 @@ [button setTitleColor:[LinphoneUtils getDictEntry:attributes key:@"title-color-disabled-highlighted"] forState:UIControlStateDisabled | UIControlStateHighlighted]; [button setTitleColor:[LinphoneUtils getDictEntry:attributes key:@"title-color-selected-highlighted"] forState:UIControlStateSelected | UIControlStateHighlighted]; [button setTitleColor:[LinphoneUtils getDictEntry:attributes key:@"title-color-selected-disabled"] forState:UIControlStateSelected | UIControlStateDisabled]; - + [button setTitleEdgeInsets:UIEdgeInsetsFromString([LinphoneUtils getDictEntry:attributes key:@"title-edge"])]; [button setContentEdgeInsets:UIEdgeInsetsFromString([LinphoneUtils getDictEntry:attributes key:@"content-edge"])]; [button setImageEdgeInsets:UIEdgeInsetsFromString([LinphoneUtils getDictEntry:attributes key:@"image-edge"])]; @@ -202,7 +192,7 @@ [button setImage:[LinphoneUtils getDictEntry:attributes key:@"image-disabled-highlighted"] forState:UIControlStateDisabled | UIControlStateHighlighted]; [button setImage:[LinphoneUtils getDictEntry:attributes key:@"image-selected-highlighted"] forState:UIControlStateSelected | UIControlStateHighlighted]; [button setImage:[LinphoneUtils getDictEntry:attributes key:@"image-selected-disabled"] forState:UIControlStateSelected | UIControlStateDisabled]; - + [button setBackgroundImage:[LinphoneUtils getDictEntry:attributes key:@"background-normal"] forState:UIControlStateNormal]; [button setBackgroundImage:[LinphoneUtils getDictEntry:attributes key:@"background-highlighted"] forState:UIControlStateHighlighted]; [button setBackgroundImage:[LinphoneUtils getDictEntry:attributes key:@"background-disabled"] forState:UIControlStateDisabled]; @@ -241,34 +231,9 @@ if (floatSize < 1023) return([NSString stringWithFormat:@"%1.1f MB",floatSize]); floatSize = floatSize / 1024; - + return([NSString stringWithFormat:@"%1.1f GB",floatSize]); } + @end - -#define LOGV(level, argstart) \ - va_list args; \ - va_start(args, argstart); \ - [LinphoneLogger logv:level format:argstart args:args]; \ - va_end(args); - -void LOGI(NSString* format, ...){ - LOGV(LinphoneLoggerLog, format); -} - -void LOGD(NSString* format, ...){ - LOGV(LinphoneLoggerDebug, format); -} - -void LOGW(NSString* format, ...){ - LOGV(LinphoneLoggerWarning, format); -} - -void LOGE(NSString* format, ...){ - LOGV(LinphoneLoggerError, format); -} - -void LOGF(NSString* format, ...){ - LOGV(LinphoneLoggerFatal, format); -} From 0909bb2909a49dd3f8b6806346b439e0eaa77f37 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 17 Apr 2015 10:51:03 +0200 Subject: [PATCH 08/29] continue --- Classes/DialerViewController.m | 1 + Classes/InAppProductsManager.h | 21 +++- Classes/InAppProductsManager.m | 117 ++++++++++++++++----- Classes/InAppProductsTableViewController.m | 25 ++++- Classes/InAppProductsViewController.h | 1 + Classes/InAppProductsViewController.m | 3 + Classes/InAppProductsViewController.xib | 14 ++- Classes/LinphoneManager.m | 5 +- linphone-Info.plist | 2 +- 9 files changed, 152 insertions(+), 37 deletions(-) diff --git a/Classes/DialerViewController.m b/Classes/DialerViewController.m index 4141ed3dd..9d1554211 100644 --- a/Classes/DialerViewController.m +++ b/Classes/DialerViewController.m @@ -292,6 +292,7 @@ static UICompositeViewDescription *compositeDescription = nil; LOGE(@"Cannot sent logs: file is NULL"); return; } + NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]; NSString *filename = [appName stringByAppendingString:@".gz"]; NSString *mimeType = @"text/plain"; diff --git a/Classes/InAppProductsManager.h b/Classes/InAppProductsManager.h index 03927caf1..352e7ae79 100644 --- a/Classes/InAppProductsManager.h +++ b/Classes/InAppProductsManager.h @@ -20,15 +20,28 @@ #import #import -extern NSString *const kInAppProductsReady; +extern NSString *const kLinphoneIAPurchaseNotification; -@interface InAppProductsManager : NSObject { +@interface InAppProductsManager : NSObject -} +#define IAPAvailableSucceeded @"IAPAvailableSucceeded" +#define IAPAvailableFailed @"IAPAvailableFailed" +#define IAPPurchaseFailed @"IAPPurchaseFailed" +#define IAPPurchaseSucceeded @"IAPPurchaseSucceeded" +#define IAPRestoreFailed @"IAPRestoreFailed" +#define IAPRestoreSucceeded @"IAPRestoreSucceeded" +typedef NSString* IAPPurchaseNotificationStatus; -@property (readonly) NSArray *inAppProducts; +@property (nonatomic, retain) IAPPurchaseNotificationStatus status; +@property (nonatomic, copy) NSString *errlast; + +@property (nonatomic, strong) NSMutableArray *productsAvailable; +@property (nonatomic, strong) NSMutableArray *productsPurchased; +@property (nonatomic, strong) NSMutableArray *productsRestored; - (void)loadProducts; - (BOOL)isPurchased:(SKProduct*)product; - (void)purchaseWithID:(NSString*)productId; +- (void)restore; + @end diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index 3a0faa3a3..8ec9adcf4 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -20,7 +20,7 @@ #import "InAppProductsManager.h" #import "Utils.h" -NSString *const kInAppProductsReady = @"InAppProductsReady"; +NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotification"; @implementation InAppProductsManager { bool ready; @@ -39,7 +39,7 @@ NSString *const kInAppProductsReady = @"InAppProductsReady"; return; } //TODO: move this list elsewhere - NSArray * list = [[NSArray alloc] initWithArray:@[@"test.tunnel"]]; + NSArray * list = [[[NSArray alloc] initWithArray:@[@"test.tunnel"]] autorelease]; SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithArray:list]]; @@ -49,39 +49,108 @@ NSString *const kInAppProductsReady = @"InAppProductsReady"; - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { - _inAppProducts = [response.products retain]; - LOGI(@"Found %lu products purchasable", (unsigned long)_inAppProducts.count); + _productsAvailable= [[NSMutableArray arrayWithArray: response.products] retain]; - for (NSString *invalidIdentifier in response.invalidProductIdentifiers) { - LOGE(@"Product Identifier with invalid ID %@", invalidIdentifier); + LOGI(@"Found %lu products available", (unsigned long)_productsAvailable.count); + + if (response.invalidProductIdentifiers.count > 0) { + for (NSString *invalidIdentifier in response.invalidProductIdentifiers) { + LOGW(@"Found product Identifier with invalid ID '%@'", invalidIdentifier); + } + [self postNotificationforStatus:IAPAvailableFailed]; + } else { + [self postNotificationforStatus:IAPAvailableSucceeded]; } - ready = true; - - NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: - _inAppProducts, @"products", - nil]; - - dispatch_async(dispatch_get_main_queue(), ^(void){ - [[NSNotificationCenter defaultCenter] postNotificationName:kInAppProductsReady object:self userInfo:dict]; - }); -} - -- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { - } - (BOOL)isPurchased:(SKProduct*)product { - for (SKProduct *prod in _inAppProducts) { + for (SKProduct *prod in _productsPurchased) { if (prod == product) { - LOGE(@"Is %@ bought? assuming NO", product.localizedTitle); - return false; //todo + bool isBought = true; + LOGE(@"%@ is %s bought.", product.localizedTitle, isBought?"":"NOT"); + return isBought; } } return false; } - (void)purchaseWithID:(NSString *)productId { - + for (SKProduct *product in _productsAvailable) { + if ([product.productIdentifier compare:productId options:NSLiteralSearch] == NSOrderedSame) { + SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product]; + [[SKPaymentQueue defaultQueue] addPayment:payment]; + return; + } + } + [self postNotificationforStatus:IAPPurchaseFailed]; } -@end \ No newline at end of file +-(void)restore { + _productsRestored = [[NSMutableArray alloc] initWithCapacity:0]; + [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; +} + +- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { + for(SKPaymentTransaction * transaction in transactions) { + switch (transaction.transactionState) { + case SKPaymentTransactionStatePurchasing: + break; + case SKPaymentTransactionStatePurchased: + case SKPaymentTransactionStateRestored: + [_productsPurchased addObject:transaction]; + [self completeTransaction:transaction forStatus:IAPPurchaseSucceeded]; + break; + default: + _errlast = [NSString stringWithFormat:@"Purchase of %@ failed.",transaction.payment.productIdentifier]; + [self completeTransaction:transaction forStatus:IAPPurchaseFailed]; + break; + } + } +} + +- (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray *)transactions { + for(SKPaymentTransaction * transaction in transactions) { + NSLog(@"%@ was removed from the payment queue.", transaction.payment.productIdentifier); + } +} + +- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error { + if (error.code != SKErrorPaymentCancelled) { + _errlast = [error localizedDescription]; + [self postNotificationforStatus:IAPRestoreFailed]; + } +} + +- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue +{ + LOGI(@"All restorable transactions have been processed by the payment queue."); +// for (SKPayment *payment in queue) { +// [queue transactions] +// [_productsRestored addObject:payment.productIdentifier]; +// } + + for (SKPaymentTransaction *transaction in queue.transactions) { + NSString *productID = transaction.payment.productIdentifier; + [_productsRestored addObject:productID]; + NSLog (@"product id is %@" , productID); + } +} + +-(void)postNotificationforStatus:(IAPPurchaseNotificationStatus)status { + _status = status; + [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneIAPurchaseNotification object:self]; + LOGI(@"Triggering notification for status %@", status); +} + +-(void)completeTransaction:(SKPaymentTransaction *)transaction forStatus:(IAPPurchaseNotificationStatus)status { + if (transaction.error.code != SKErrorPaymentCancelled) { + [self postNotificationforStatus:status]; + } else { + _status = status; + } + + // Remove the transaction from the queue for purchased and restored statuses + [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; +} + +@end diff --git a/Classes/InAppProductsTableViewController.m b/Classes/InAppProductsTableViewController.m index 0101ab94f..ec5d4362d 100644 --- a/Classes/InAppProductsTableViewController.m +++ b/Classes/InAppProductsTableViewController.m @@ -20,7 +20,25 @@ - (void)viewWillAppear:(BOOL)animated { iapm = [[LinphoneManager instance] iapManager]; currentExpanded = -1; - [iapm loadProducts]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(onIAPPurchaseNotification:) + name:kLinphoneIAPurchaseNotification + object:nil]; +} + +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + + [[NSNotificationCenter defaultCenter] removeObserver:self + name:kLinphoneIAPurchaseNotification + object:nil]; +} + +- (void)onIAPPurchaseNotification:(NSNotification*)notif { + if ([[iapm status] isEqual: IAPAvailableSucceeded]) { + [[self tableView] reloadData]; + } } #pragma mark - Table view data source @@ -30,7 +48,7 @@ } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return [iapm inAppProducts].count; + return [iapm productsAvailable].count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { @@ -39,7 +57,7 @@ if (cell == nil) { cell = [[[InAppProductsCell alloc] initWithIdentifier:kCellId maximized:(currentExpanded == indexPath.row)] autorelease]; } - SKProduct *prod = [[[[LinphoneManager instance] iapManager] inAppProducts] objectAtIndex:indexPath.row]; + SKProduct *prod = [[[[LinphoneManager instance] iapManager] productsAvailable] objectAtIndex:indexPath.row]; [cell.ptitle setText: [prod localizedTitle]]; [cell.pdescription setText: [prod localizedDescription]]; [cell.pprice setText: [NSString stringWithFormat:@"%@", [prod price]]]; @@ -75,6 +93,7 @@ [alert release]; } else { //try to purchase item, and if successfull change the switch + LOGI(@"Trying to purchase %@", cell.productID); [[[LinphoneManager instance] iapManager] purchaseWithID: cell.productID]; } } diff --git a/Classes/InAppProductsViewController.h b/Classes/InAppProductsViewController.h index 632240657..85fbd4e6d 100644 --- a/Classes/InAppProductsViewController.h +++ b/Classes/InAppProductsViewController.h @@ -14,5 +14,6 @@ } @property (nonatomic, retain) IBOutlet InAppProductsTableViewController* tableController; +- (IBAction)onRestoreClicked:(UIButton *)sender; @end diff --git a/Classes/InAppProductsViewController.m b/Classes/InAppProductsViewController.m index 67dab35cd..980350927 100644 --- a/Classes/InAppProductsViewController.m +++ b/Classes/InAppProductsViewController.m @@ -67,4 +67,7 @@ static UICompositeViewDescription *compositeDescription = nil; return compositeDescription; } +- (IBAction)onRestoreClicked:(UIButton *)sender { + [[[LinphoneManager instance] iapManager] restore]; +} @end \ No newline at end of file diff --git a/Classes/InAppProductsViewController.xib b/Classes/InAppProductsViewController.xib index d6893f211..e90f0bf64 100644 --- a/Classes/InAppProductsViewController.xib +++ b/Classes/InAppProductsViewController.xib @@ -16,8 +16,8 @@ - - + + @@ -25,6 +25,16 @@ + diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index b5cd31873..2fcd65cd3 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -271,7 +271,8 @@ struct codec_name_pref_table codec_pref_table[]={ [LinphoneLogger logc:LinphoneLoggerError format:"cannot register route change handler [%ld]",lStatus]; } - + _iapManager = [[InAppProductsManager alloc] init]; + NSString *path = [[NSBundle mainBundle] pathForResource:@"msg" ofType:@"wav"]; self.messagePlayer = [[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:path] error:nil] autorelease]; @@ -1283,8 +1284,6 @@ static LinphoneCoreVTable linphonec_vtable = { [_contactSipField release]; _contactSipField = [[self lpConfigStringForKey:@"contact_im_type_value" withDefault:@"SIP"] retain]; - _iapManager = [[InAppProductsManager alloc] init]; - fastAddressBook = [[FastAddressBook alloc] init]; linphone_core_set_root_ca(theLinphoneCore, lRootCa); diff --git a/linphone-Info.plist b/linphone-Info.plist index 1fd8768b6..964a1563d 100644 --- a/linphone-Info.plist +++ b/linphone-Info.plist @@ -53,7 +53,7 @@ CFBundleVersion - 1 + 2 LSRequiresIPhoneOS UIApplicationExitsOnSuspend From b4d9f692958dd97ac4356a7f4708f50fb9d9d209 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 17 Apr 2015 11:33:02 +0200 Subject: [PATCH 09/29] continue --- Classes/InAppProductsManager.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index 8ec9adcf4..9fc3fc8a6 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -39,7 +39,7 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati return; } //TODO: move this list elsewhere - NSArray * list = [[[NSArray alloc] initWithArray:@[@"test.tunnel"]] autorelease]; + NSArray * list = [[[NSArray alloc] initWithArray:@[@"test.auto_renew_7days", @"test.non_renew", @"test.one_time", @"test.auto_renew_1month_withfree"]] autorelease]; SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithArray:list]]; @@ -86,6 +86,8 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati } -(void)restore { + LOGI(@"Restoring user purchases..."); + if (! [SKPaymentQueue canMakePayments]) { LOGF(@"Not allowed to do in app purchase!!!"); } _productsRestored = [[NSMutableArray alloc] initWithCapacity:0]; [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; } From aefc92a0ddd3f0a1dc3605c9791ab73a5cf36131 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 17 Apr 2015 11:33:29 +0200 Subject: [PATCH 10/29] logging: everyone use LOGx functions to log --- Classes/ChatRoomTableViewController.m | 2 +- Classes/ChatRoomViewController.m | 19 ++- Classes/ContactDetailsTableViewController.m | 94 +++++------ Classes/ContactDetailsViewController.m | 74 ++++----- Classes/ContactsTableViewController.m | 2 +- Classes/ImageSharing.m | 28 ++-- Classes/InCallTableViewController.m | 64 ++++---- Classes/InCallViewController.m | 142 ++++++++-------- Classes/LinphoneAppDelegate.m | 72 ++++----- Classes/LinphoneCoreSettingsStore.m | 14 +- Classes/LinphoneManager.m | 153 +++++++++--------- Classes/LinphoneUI/UIBluetoothButton.m | 2 +- Classes/LinphoneUI/UICallCell.m | 8 +- Classes/LinphoneUI/UICamSwitch.m | 2 +- Classes/LinphoneUI/UIChatCell.m | 36 ++--- Classes/LinphoneUI/UIChatRoomCell.m | 48 +++--- .../LinphoneUI/UICompositeViewController.m | 78 ++++----- Classes/LinphoneUI/UIContactCell.m | 46 +++--- Classes/LinphoneUI/UIContactDetailsHeader.m | 68 ++++---- Classes/LinphoneUI/UIHistoryCell.m | 50 +++--- Classes/LinphoneUI/UILinphone.m | 30 ++-- Classes/LinphoneUI/UIPauseButton.m | 38 ++--- Classes/LinphoneUI/UISpeakerButton.m | 4 +- Classes/LinphoneUI/UIStateBar.m | 4 +- Classes/LinphoneUI/UIVideoButton.m | 4 +- Classes/PhoneMainView.m | 104 ++++++------ Classes/SettingsViewController.m | 126 +++++++-------- Classes/Utils/FastAddressBook.m | 6 +- Classes/Utils/Utils.h | 5 +- Classes/Utils/Utils.m | 38 ++--- Classes/WizardViewController.m | 122 +++++++------- 31 files changed, 739 insertions(+), 744 deletions(-) diff --git a/Classes/ChatRoomTableViewController.m b/Classes/ChatRoomTableViewController.m index 2780d723f..0eba8c776 100644 --- a/Classes/ChatRoomTableViewController.m +++ b/Classes/ChatRoomTableViewController.m @@ -86,7 +86,7 @@ - (void)updateChatEntry:(LinphoneChatMessage*)chat { NSInteger index = ms_list_index(self->messageList, chat); if (index<0) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"chat entry doesn't exist"]; + LOGW(@"chat entry doesn't exist"); return; } [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:FALSE]; //just reload diff --git a/Classes/ChatRoomViewController.m b/Classes/ChatRoomViewController.m index 458aa7e01..bb999d7b4 100644 --- a/Classes/ChatRoomViewController.m +++ b/Classes/ChatRoomViewController.m @@ -262,7 +262,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)update { if(chatRoom == NULL) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update chat room header: null contact"]; + LOGW(@"Cannot update chat room header: null contact"); return; } @@ -311,14 +311,13 @@ static UICompositeViewDescription *compositeDescription = nil; static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud) { ChatRoomViewController* thiz = (ChatRoomViewController*)ud; const char*text = linphone_chat_message_get_text(msg); - [LinphoneLogger log:LinphoneLoggerLog - format:@"Delivery status for [%s] is [%s]",text,linphone_chat_message_state_to_string(state)]; + LOGI(@"Delivery status for [%s] is [%s]",text,linphone_chat_message_state_to_string(state)); [thiz.tableController updateChatEntry:msg]; } - (BOOL)sendMessage:(NSString *)message withExterlBodyUrl:(NSURL*)externalUrl withInternalURL:(NSURL*)internalUrl { if(chatRoom == NULL) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot send message: No chatroom"]; + LOGW(@"Cannot send message: No chatroom"); return FALSE; } @@ -350,7 +349,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta dispatch_async(dispatch_get_main_queue(), ^{ [waitView setHidden:TRUE]; if (error) { - [LinphoneLogger log:LinphoneLoggerError format:@"Cannot save image data downloaded [%@]", [error localizedDescription]]; + LOGE(@"Cannot save image data downloaded [%@]", [error localizedDescription]); UIAlertView* errorAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Transfer error", nil) message:NSLocalizedString(@"Cannot write image to photo library", nil) @@ -361,7 +360,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta [errorAlert release]; return; } - [LinphoneLogger log:LinphoneLoggerLog format:@"Image saved to [%@]", [assetURL absoluteString]]; + LOGI(@"Image saved to [%@]", [assetURL absoluteString]); [self chatRoomStartImageUpload:image url:assetURL]; }); }]; @@ -653,7 +652,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta [transferView setHidden:TRUE]; NSString *url = [aimageSharing.connection.currentRequest.URL absoluteString]; if (aimageSharing.upload) { - [LinphoneLogger log:LinphoneLoggerError format:@"Cannot upload file to server [%@] because [%@]", url, [error localizedDescription]]; + LOGE(@"Cannot upload file to server [%@] because [%@]", url, [error localizedDescription]); UIAlertView* errorAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Transfer error", nil) message:NSLocalizedString(@"Cannot transfer file to remote contact", nil) delegate:nil @@ -662,7 +661,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta [errorAlert show]; [errorAlert release]; } else { - [LinphoneLogger log:LinphoneLoggerError format:@"Cannot download file from [%@] because [%@]", url, [error localizedDescription]]; + LOGE(@"Cannot download file from [%@] because [%@]", url, [error localizedDescription]); UIAlertView* errorAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Transfer error", nil) message:NSLocalizedString(@"Cannot transfer file from remote contact", nil) delegate:nil @@ -691,7 +690,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){ if (error) { - [LinphoneLogger log:LinphoneLoggerError format:@"Cannot save image data downloaded [%@]", [error localizedDescription]]; + LOGE(@"Cannot save image data downloaded [%@]", [error localizedDescription]); UIAlertView* errorAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Transfer error", nil) message:NSLocalizedString(@"Cannot write image to photo library", nil) @@ -702,7 +701,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta [errorAlert release]; return; } - [LinphoneLogger log:LinphoneLoggerLog format:@"Image saved to [%@]", [assetURL absoluteString]]; + LOGI(@"Image saved to [%@]", [assetURL absoluteString]); [LinphoneManager setValueInMessageAppData:[assetURL absoluteString] forKey:@"localimage" inMessage:chat]; [tableController updateChatEntry:chat]; }]; diff --git a/Classes/ContactDetailsTableViewController.m b/Classes/ContactDetailsTableViewController.m index be2b15b28..be6a18b35 100644 --- a/Classes/ContactDetailsTableViewController.m +++ b/Classes/ContactDetailsTableViewController.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "ContactDetailsTableViewController.h" #import "PhoneMainView.h" @@ -74,7 +74,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe labelArray = [[NSMutableArray alloc] initWithObjects: [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"], - [NSString stringWithString:(NSString*)kABPersonPhoneMobileLabel], + [NSString stringWithString:(NSString*)kABPersonPhoneMobileLabel], [NSString stringWithString:(NSString*)kABPersonPhoneIPhoneLabel], [NSString stringWithString:(NSString*)kABPersonPhoneMainLabel], nil]; editingIndexPath = nil; @@ -94,7 +94,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe [self initContactDetailsTableViewController]; } return self; -} +} - (void)dealloc { if(contact != nil && ABRecordGetRecordID(contact) == kABRecordInvalidID) { @@ -105,7 +105,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe } [labelArray release]; [dataCache release]; - + [super dealloc]; } @@ -116,7 +116,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe [super viewDidLoad]; [headerController view]; // Force view load [footerController view]; // Force view load - + self.tableView.accessibilityIdentifier = @"Contact numbers table"; } @@ -176,12 +176,12 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe - (void)loadData { [dataCache removeAllObjects]; - - if(contact == NULL) + + if(contact == NULL) return; - - [LinphoneLogger logc:LinphoneLoggerLog format:"Load data from contact %p", contact]; - // Phone numbers + + LOGI(@"Load data from contact %p", contact); + // Phone numbers { ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonPhoneProperty); NSMutableArray *subArray = [NSMutableArray array]; @@ -196,7 +196,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe } [dataCache addObject:subArray]; } - + // SIP (IM) { ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); @@ -237,7 +237,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe } [dataCache addObject:subArray]; } - + // Email if ([[LinphoneManager instance] lpConfigBoolForKey:@"show_contacts_emails_preference"] == true) { @@ -274,7 +274,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe } ABMultiValueIdentifier index; NSError* error = NULL; - + CFStringRef keys[] = { kABPersonInstantMessageUsernameKey, kABPersonInstantMessageServiceKey}; CFTypeRef values[] = { [value copy], [LinphoneManager instance].contactSipField }; CFDictionaryRef lDict = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 2, NULL, NULL); @@ -287,7 +287,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe } if (!ABRecordSetValue(contact, kABPersonInstantMessageProperty, lMap, (CFErrorRef*)&error)) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Can't set contact with value [%@] cause [%@]", value,[error localizedDescription]]; + LOGI(@"Can't set contact with value [%@] cause [%@]", value,[error localizedDescription]); CFRelease(lMap); } else { if (entry == nil) { @@ -314,7 +314,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe CFDictionaryRef lDict2 = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 2, NULL, NULL); ABMultiValueReplaceValueAtIndex(lMap, lDict2, index); if (!ABRecordSetValue(contact, kABPersonInstantMessageProperty, lMap, (CFErrorRef*)&error)) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Can't set contact with value [%@] cause [%@]", value,[error localizedDescription]]; + LOGI(@"Can't set contact with value [%@] cause [%@]", value,[error localizedDescription]); } CFRelease(lDict2); linphone_address_destroy(address); @@ -324,7 +324,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe CFRelease(lMap); } CFRelease(lDict); - + return entry; } @@ -354,14 +354,14 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe if(!ABMultiValueAddValueAndLabel(lMap, [[value copy] autorelease], label, &identifier)) { added = false; } - + if(added && ABRecordSetValue(contact, kABPersonPhoneProperty, lMap, (CFErrorRef*)&error)) { Entry *entry = [[Entry alloc] initWithData:identifier]; [sectionArray addObject:entry]; [entry release]; } else { added = false; - [LinphoneLogger log:LinphoneLoggerLog format:@"Can't add entry: %@", [error localizedDescription]]; + LOGI(@"Can't add entry: %@", [error localizedDescription]); } CFRelease(lMap); } else if(contactSections[section] == ContactSections_Sip) { @@ -371,7 +371,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe added=true; } else { added=false; - [LinphoneLogger log:LinphoneLoggerError format:@"Can't add entry for value: %@", value]; + LOGE(@"Can't add entry for value: %@", value); } } else if(contactSections[section] == ContactSections_Email) { ABMultiValueIdentifier identifier; @@ -387,18 +387,18 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe if(!ABMultiValueAddValueAndLabel(lMap, [[value copy] autorelease], label, &identifier)) { added = false; } - + if(added && ABRecordSetValue(contact, kABPersonEmailProperty, lMap, (CFErrorRef*)&error)) { Entry *entry = [[Entry alloc] initWithData:identifier]; [sectionArray addObject:entry]; [entry release]; } else { added = false; - [LinphoneLogger log:LinphoneLoggerLog format:@"Can't add entry: %@", [error localizedDescription]]; + LOGI(@"Can't add entry: %@", [error localizedDescription]); } CFRelease(lMap); } - + if (added && animated) { // Update accessory if (count > 0) { @@ -456,7 +456,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe } [sectionArray removeObjectAtIndex:[indexPath row]]; - + NSArray *tagInsertIndexPath = [NSArray arrayWithObject:indexPath]; if (animated) { [tableview deleteRowsAtIndexPaths:tagInsertIndexPath withRowAnimation:UITableViewRowAnimationFade]; @@ -507,26 +507,26 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *kCellId = @"ContactDetailsCell"; UIEditableTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; - if (cell == nil) { + if (cell == nil) { cell = [[[UIEditableTableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:kCellId] autorelease]; [cell.detailTextField setDelegate:self]; [cell.detailTextField setAutocapitalizationType:UITextAutocapitalizationTypeNone]; [cell.detailTextField setAutocorrectionType:UITextAutocorrectionTypeNo]; [cell setBackgroundColor:[UIColor whiteColor]]; - + // Background View UACellBackgroundView *selectedBackgroundView = [[[UACellBackgroundView alloc] initWithFrame:CGRectZero] autorelease]; cell.selectedBackgroundView = selectedBackgroundView; [selectedBackgroundView setBackgroundColor:LINPHONE_TABLE_CELL_BACKGROUND_COLOR]; } - + NSMutableArray *sectionDict = [self getSectionData:[indexPath section]]; Entry *entry = [sectionDict objectAtIndex:[indexPath row]]; - + NSString *value = @""; // default label is our app name NSString *label = [ContactDetailsTableViewController localizeLabel:[labelArray objectAtIndex:0]]; - + if(contactSections[[indexPath section]] == ContactSections_Number) { ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonPhoneProperty); NSInteger index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); @@ -701,7 +701,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe [headerController setEditing:editing animated:animated]; [footerController setEditing:editing animated:animated]; - + if(animated) { [self.tableView beginUpdates]; } @@ -732,7 +732,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe if(animated) { [self.tableView endUpdates]; } - + [super setEditing:editing animated:animated]; if(contactDetailsDelegate != nil) { [contactDetailsDelegate onModification:nil]; @@ -747,7 +747,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe return UITableViewCellEditingStyleDelete; } -- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { +- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if(section == ContactSections_None) { return [headerController view]; } else { @@ -755,7 +755,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe } } -- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { +- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { if(section == (ContactSections_MAX - 1)) { if(ABRecordGetRecordID(contact) != kABRecordInvalidID) { return [footerController view]; @@ -781,14 +781,14 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe return nil; } -- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if(section == ContactSections_None) { return [UIContactDetailsHeader height:[headerController isEditing]]; } else { // Hide section if nothing in it if([[self getSectionData:section] count] > 0) return 22; - else + else return 0.000001f; // Hack UITableView = 0 } } @@ -846,12 +846,12 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe } - (BOOL)textFieldShouldReturn:(UITextField *)textField { - [textField resignFirstResponder]; + [textField resignFirstResponder]; return YES; } - (BOOL)textFieldShouldEndEditing:(UITextField *)textField { - UIView *view = [textField superview]; + UIView *view = [textField superview]; // Find TableViewCell while(view != nil && ![view isKindOfClass:[UIEditableTableViewCell class]]) view = [view superview]; if(view != nil) { @@ -878,7 +878,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe [cell.detailTextLabel setText:value]; } else { - [LinphoneLogger logc:LinphoneLoggerError format:"Not valid UIEditableTableViewCell"]; + LOGE(@"Not valid UIEditableTableViewCell"); } if(contactDetailsDelegate != nil) { [self performSelector:@selector(updateModification) withObject:nil afterDelay:0]; diff --git a/Classes/ContactDetailsViewController.m b/Classes/ContactDetailsViewController.m index 35f010ae3..d37ab5384 100644 --- a/Classes/ContactDetailsViewController.m +++ b/Classes/ContactDetailsViewController.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "ContactDetailsViewController.h" #import "PhoneMainView.h" @@ -47,16 +47,16 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf ABAddressBookUnregisterExternalChangeCallback(addressBook, sync_address_book, self); CFRelease(addressBook); [tableController release]; - + [editButton release]; [backButton release]; [cancelButton release]; - + [super dealloc]; } -#pragma mark - +#pragma mark - - (void)resetData { [self disableEdit:FALSE]; @@ -64,8 +64,8 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf ABAddressBookRevert(addressBook); return; } - - [LinphoneLogger logc:LinphoneLoggerLog format:"Reset data to contact %p", contact]; + + LOGI(@"Reset data to contact %p", contact); ABRecordID recordID = ABRecordGetRecordID(contact); ABAddressBookRevert(addressBook); contact = ABAddressBookGetPersonWithRecordID(addressBook, recordID); @@ -88,27 +88,27 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf [[PhoneMainView instance] popCurrentView]; return; } - + // Remove contact from book if(ABRecordGetRecordID(contact) != kABRecordInvalidID) { NSError* error = NULL; ABAddressBookRemoveRecord(addressBook, contact, (CFErrorRef*)&error); if (error != NULL) { - [LinphoneLogger log:LinphoneLoggerError format:@"Remove contact %p: Fail(%@)", contact, [error localizedDescription]]; + LOGE(@"Remove contact %p: Fail(%@)", contact, [error localizedDescription]); } else { - [LinphoneLogger logc:LinphoneLoggerLog format:"Remove contact %p: Success!", contact]; + LOGI(@"Remove contact %p: Success!", contact); } contact = NULL; - + // Save address book error = NULL; inhibUpdate = TRUE; ABAddressBookSave(addressBook, (CFErrorRef*)&error); inhibUpdate = FALSE; if (error != NULL) { - [LinphoneLogger log:LinphoneLoggerError format:@"Save AddressBook: Fail(%@)", [error localizedDescription]]; + LOGE(@"Save AddressBook: Fail(%@)", [error localizedDescription]); } else { - [LinphoneLogger logc:LinphoneLoggerLog format:"Save AddressBook: Success!"]; + LOGI(@"Save AddressBook: Success!"); } [[LinphoneManager instance].fastAddressBook reload]; } @@ -119,27 +119,27 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf [[PhoneMainView instance] popCurrentView]; return; } - + // Add contact to book NSError* error = NULL; if(ABRecordGetRecordID(contact) == kABRecordInvalidID) { ABAddressBookAddRecord(addressBook, contact, (CFErrorRef*)&error); if (error != NULL) { - [LinphoneLogger log:LinphoneLoggerError format:@"Add contact %p: Fail(%@)", contact, [error localizedDescription]]; + LOGE(@"Add contact %p: Fail(%@)", contact, [error localizedDescription]); } else { - [LinphoneLogger logc:LinphoneLoggerLog format:"Add contact %p: Success!", contact]; + LOGI(@"Add contact %p: Success!", contact); } } - + // Save address book error = NULL; inhibUpdate = TRUE; ABAddressBookSave(addressBook, (CFErrorRef*)&error); inhibUpdate = FALSE; if (error != NULL) { - [LinphoneLogger log:LinphoneLoggerError format:@"Save AddressBook: Fail(%@)", [error localizedDescription]]; + LOGE(@"Save AddressBook: Fail(%@)", [error localizedDescription]); } else { - [LinphoneLogger logc:LinphoneLoggerLog format:"Save AddressBook: Success!"]; + LOGI(@"Save AddressBook: Success!"); } [[LinphoneManager instance].fastAddressBook reload]; } @@ -202,15 +202,15 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf - (void)viewDidLoad{ [super viewDidLoad]; - + // Set selected+over background: IB lack ! [editButton setBackgroundImage:[UIImage imageNamed:@"contact_ok_over.png"] forState:(UIControlStateHighlighted | UIControlStateSelected)]; - + // Set selected+disabled background: IB lack ! [editButton setBackgroundImage:[UIImage imageNamed:@"contact_ok_disabled.png"] forState:(UIControlStateDisabled | UIControlStateSelected)]; - + [LinphoneUtils buttonFixStates:editButton]; [tableController.tableView setBackgroundColor:[UIColor clearColor]]; // Can't do it in Xib: issue with ios4 @@ -233,12 +233,12 @@ static UICompositeViewDescription *compositeDescription = nil; + (UICompositeViewDescription *)compositeViewDescription { if(compositeDescription == nil) { - compositeDescription = [[UICompositeViewDescription alloc] init:@"ContactDetails" - content:@"ContactDetailsViewController" - stateBar:nil - stateBarEnabled:false - tabBar:@"UIMainBar" - tabBarEnabled:true + compositeDescription = [[UICompositeViewDescription alloc] init:@"ContactDetails" + content:@"ContactDetailsViewController" + stateBar:nil + stateBarEnabled:false + tabBar:@"UIMainBar" + tabBarEnabled:true fullscreen:false landscapeMode:[LinphoneManager runningOnIpad] portraitMode:true]; diff --git a/Classes/ContactsTableViewController.m b/Classes/ContactsTableViewController.m index 79675a18d..a87dbfd0d 100644 --- a/Classes/ContactsTableViewController.m +++ b/Classes/ContactsTableViewController.m @@ -127,7 +127,7 @@ static int ms_strcmpfuz(const char * fuzzy_word, const char * sentence) { } - (void)loadData { - [LinphoneLogger logc:LinphoneLoggerLog format:"Load contact list"]; + LOGI(@"Load contact list"); @synchronized (addressBookMap) { // Reset Address book diff --git a/Classes/ImageSharing.m b/Classes/ImageSharing.m index 0b41cfc6c..42742a031 100644 --- a/Classes/ImageSharing.m +++ b/Classes/ImageSharing.m @@ -73,7 +73,7 @@ - (void)cancel { [connection cancel]; - [LinphoneLogger log:LinphoneLoggerLog format:@"File transfer interrupted by user"]; + LOGI(@"File transfer interrupted by user"); if(delegate) { [delegate imageSharingAborted:self]; } @@ -81,36 +81,36 @@ - (void)downloadImageFrom:(NSURL*)url { - [LinphoneLogger log:LinphoneLoggerLog format:@"downloading [%@]", [url absoluteString]]; - + LOGI(@"downloading [%@]", [url absoluteString]); + NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; - + connection = [[NSURLConnection alloc] initWithRequest:request delegate: self]; } - (void)uploadImageTo:(NSURL*)url image:(UIImage*)image { - [LinphoneLogger log:LinphoneLoggerLog format:@"downloading [%@]", [url absoluteString]]; - + LOGI(@"downloading [%@]", [url absoluteString]); + // setting up the request object now NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:url]; [request setHTTPMethod:@"POST"]; - + /* add some header info now we always need a boundary when we post a file also we need to set the content type - + You might want to generate a random boundary.. this is just the same as my output from wireshark on a valid html post */ NSString *boundary = @"---------------------------14737809831466499882746641449"; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; - + /* now lets create the body of the post */ @@ -122,7 +122,7 @@ [body appendData:[NSData dataWithData:UIImageJPEGRepresentation(image, 1.0)]]; [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [request setHTTPBody:body]; - + connection = [[NSURLConnection alloc] initWithRequest:(NSURLRequest *)request delegate:self]; } @@ -152,8 +152,8 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse *) response; statusCode = httpResponse.statusCode; - [LinphoneLogger log:LinphoneLoggerLog format:@"File transfer status code [%i]", statusCode]; - + LOGI(@"File transfer status code [%i]", statusCode); + if (statusCode == 200 && !upload) { totalBytesExpectedToRead = (int)[response expectedContentLength]; } @@ -169,14 +169,14 @@ } if (upload) { NSString* imageRemoteUrl = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - [LinphoneLogger log:LinphoneLoggerLog format:@"File can be downloaded from [%@]", imageRemoteUrl]; + LOGI(@"File can be downloaded from [%@]", imageRemoteUrl); if(delegate) { [delegate imageSharingUploadDone:self url:[NSURL URLWithString:imageRemoteUrl]]; } [imageRemoteUrl release]; } else { UIImage* image = [UIImage imageWithData:data]; - [LinphoneLogger log:LinphoneLoggerLog format:@"File downloaded"]; + LOGI(@"File downloaded"); if(delegate) { [delegate imageSharingDownloadDone:self image:image]; } diff --git a/Classes/InCallTableViewController.m b/Classes/InCallTableViewController.m index cd47bfd43..6993a3cb0 100644 --- a/Classes/InCallTableViewController.m +++ b/Classes/InCallTableViewController.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "InCallTableViewController.h" #import "UICallCell.h" @@ -60,7 +60,7 @@ enum TableSection { [self initInCallTableViewController]; } return self; -} +} - (void)dealloc { [super dealloc]; @@ -71,9 +71,9 @@ enum TableSection { - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; updateTime = [NSTimer scheduledTimerWithTimeInterval:1 - target:self - selector:@selector(update) - userInfo:nil + target:self + selector:@selector(update) + userInfo:nil repeats:YES]; } @@ -97,7 +97,7 @@ enum TableSection { + (int)callCount:(LinphoneCore*) lc { int count = 0; const MSList* calls = linphone_core_get_calls(lc); - + while (calls != 0) { if (![InCallTableViewController isInConference:((LinphoneCall*)calls->data)]) { count++; @@ -109,7 +109,7 @@ enum TableSection { + (LinphoneCall*)retrieveCallAtIndex: (NSInteger) index inConference:(bool) conf{ const MSList* calls = linphone_core_get_calls([LinphoneManager getLc]); - + while (calls != 0) { if ([InCallTableViewController isInConference:(LinphoneCall*)calls->data] == conf) { if (index == 0) @@ -118,9 +118,9 @@ enum TableSection { } calls = calls->next; } - + if (calls == 0) { - [LinphoneLogger logc:LinphoneLoggerError format:"Cannot find call with index %d (in conf: %d)", index, conf]; + LOGE(@"Cannot find call with index %d (in conf: %d)", index, conf); return nil; } else { return (LinphoneCall*)calls->data; @@ -128,7 +128,7 @@ enum TableSection { } -#pragma mark - +#pragma mark - - (void)removeCallData:(LinphoneCall*) call { // Remove data associated with the call @@ -174,7 +174,7 @@ enum TableSection { for (int row = 0; row < [tableView numberOfRowsInSection:section]; row++) { NSIndexPath* cellPath = [NSIndexPath indexPathForRow:row inSection:section]; UICallCell* cell = (UICallCell*) [tableView cellForRowAtIndexPath:cellPath]; - [cell update]; + [cell update]; } } } @@ -216,14 +216,14 @@ enum TableSection { if (cell == nil) { cell = [[[UICallCell alloc] initWithIdentifier:kCellId] autorelease]; } - + bool inConference = indexPath.section == ConferenceSection; - + LinphoneCore* lc = [LinphoneManager getLc]; LinphoneCall* currentCall = linphone_core_get_current_call(lc); LinphoneCall* call = [InCallTableViewController retrieveCallAtIndex:indexPath.row inConference:inConference]; [cell setData:[self addCallData:call]]; - + // Update cell if ([indexPath section] == CallSection && [indexPath row] == 0 && linphone_core_get_conference_size(lc) == 0) { [cell setFirstCell:true]; @@ -233,20 +233,20 @@ enum TableSection { [cell setCurrentCall:(currentCall == call)]; [cell setConferenceCell:inConference]; [cell update]; - + /*if (linphone_core_get_calls_nb(lc) > 1 || linphone_core_get_conference_size(lc) > 0) { tableView.scrollEnabled = true; } else { tableView.scrollEnabled = false; }*/ return cell; -} +} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { int count = 0; - + LinphoneCore* lc = [LinphoneManager getLc]; - + if(section == CallSection) { count = [InCallTableViewController callCount:lc]; } else { @@ -273,7 +273,7 @@ enum TableSection { #pragma mark - UITableViewDelegate Functions -- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { +- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if(section == CallSection) { return [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; } else if(section == ConferenceSection) { @@ -291,11 +291,11 @@ enum TableSection { return [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; } -- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { +- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; } -- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { LinphoneCore* lc = [LinphoneManager getLc]; if(section == CallSection) { return 0.000001f; // Hack UITableView = 0 @@ -307,7 +307,7 @@ enum TableSection { return 0.000001f; // Hack UITableView = 0 } -- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { +- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { LinphoneCore* lc = [LinphoneManager getLc]; if(section == CallSection) { return 0.000001f; // Hack UITableView = 0 diff --git a/Classes/InCallViewController.m b/Classes/InCallViewController.m index fda5ce633..f87171408 100644 --- a/Classes/InCallViewController.m +++ b/Classes/InCallViewController.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import #import @@ -67,7 +67,7 @@ const NSInteger SECURE_BUTTON_TAG=5; - (void)dealloc { [callTableController release]; [callTableView release]; - + [videoGroup release]; [videoView release]; [videoPreview release]; @@ -75,17 +75,17 @@ const NSInteger SECURE_BUTTON_TAG=5; [testVideoView release]; #endif [videoCameraSwitch release]; - + [videoWaitingForFirstImage release]; - + [videoZoomHandler release]; - + [[PhoneMainView instance].view removeGestureRecognizer:singleFingerTap]; [singleFingerTap release]; - + // Remove all observer [[NSNotificationCenter defaultCenter] removeObserver:self]; - + [super dealloc]; } @@ -96,12 +96,12 @@ static UICompositeViewDescription *compositeDescription = nil; + (UICompositeViewDescription *)compositeViewDescription { if(compositeDescription == nil) { - compositeDescription = [[UICompositeViewDescription alloc] init:@"InCall" - content:@"InCallViewController" - stateBar:@"UIStateBar" - stateBarEnabled:true - tabBar:@"UICallBar" - tabBarEnabled:true + compositeDescription = [[UICompositeViewDescription alloc] init:@"InCall" + content:@"InCallViewController" + stateBar:@"UIStateBar" + stateBarEnabled:true + tabBar:@"UICallBar" + tabBarEnabled:true fullscreen:false landscapeMode:true portraitMode:true]; @@ -115,7 +115,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - + [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; UIDevice *device = [UIDevice currentDevice]; device.proximityMonitoringEnabled = YES; @@ -130,14 +130,14 @@ static UICompositeViewDescription *compositeDescription = nil; [hideControlsTimer invalidate]; hideControlsTimer = nil; } - + if( hiddenVolume ) { [[PhoneMainView instance] setVolumeHidden:FALSE]; hiddenVolume = FALSE; } - + // Remove observer - [[NSNotificationCenter defaultCenter] removeObserver:self + [[NSNotificationCenter defaultCenter] removeObserver:self name:kLinphoneCallUpdate object:nil]; } @@ -145,11 +145,11 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // Set observer - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(callUpdateEvent:) + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(callUpdateEvent:) name:kLinphoneCallUpdate object:nil]; - + // Update on show LinphoneCall* call = linphone_core_get_current_call([LinphoneManager getLc]); LinphoneCallState state = (call != NULL)?linphone_call_get_state(call): 0; @@ -158,14 +158,14 @@ static UICompositeViewDescription *compositeDescription = nil; // Set windows (warn memory leaks) linphone_core_set_native_video_window_id([LinphoneManager getLc], (unsigned long)videoView); linphone_core_set_native_preview_window_id([LinphoneManager getLc], (unsigned long)videoPreview); - + // Enable tap [singleFingerTap setEnabled:TRUE]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; - + [[UIApplication sharedApplication] setIdleTimerDisabled:false]; UIDevice *device = [UIDevice currentDevice]; device.proximityMonitoringEnabled = NO; @@ -177,16 +177,16 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewDidLoad { [super viewDidLoad]; - + [singleFingerTap setNumberOfTapsRequired:1]; [singleFingerTap setCancelsTouchesInView: FALSE]; [[PhoneMainView instance].view addGestureRecognizer:singleFingerTap]; - + [videoZoomHandler setup:videoGroup]; videoGroup.alpha = 0; - + [videoCameraSwitch setPreview:videoPreview]; - + [callTableController.tableView setBackgroundColor:[UIColor clearColor]]; // Can't do it in Xib: issue with ios4 [callTableController.tableView setBackgroundView:nil]; // Can't do it in Xib: issue with ios4 } @@ -213,16 +213,16 @@ static UICompositeViewDescription *compositeDescription = nil; } // Update table - [callTableView reloadData]; - + [callTableView reloadData]; + // Fake call update if(call == NULL) { return; } - switch (state) { - case LinphoneCallIncomingReceived: - case LinphoneCallOutgoingInit: + switch (state) { + case LinphoneCallIncomingReceived: + case LinphoneCallOutgoingInit: { if(linphone_core_get_calls_nb(lc) > 1) { [callTableController minimizeAll]; @@ -258,10 +258,10 @@ static UICompositeViewDescription *compositeDescription = nil; { const LinphoneCallParams* current = linphone_call_get_current_params(call); const LinphoneCallParams* remote = linphone_call_get_remote_params(call); - + /* remote wants to add video */ if (linphone_core_video_enabled(lc) && !linphone_call_params_video_enabled(current) && - linphone_call_params_video_enabled(remote) && + linphone_call_params_video_enabled(remote) && !linphone_core_get_video_policy(lc)->automatically_accept) { linphone_core_defer_call_update(lc, call); [self displayAskToEnableVideoCall:call]; @@ -288,7 +288,7 @@ static UICompositeViewDescription *compositeDescription = nil; default: break; } - + } - (void)showControls:(id)sender { @@ -296,7 +296,7 @@ static UICompositeViewDescription *compositeDescription = nil; [hideControlsTimer invalidate]; hideControlsTimer = nil; } - + if([[[PhoneMainView instance] currentView] equal:[InCallViewController compositeViewDescription]] && videoShown) { // show controls [UIView beginAnimations:nil context:nil]; @@ -306,7 +306,7 @@ static UICompositeViewDescription *compositeDescription = nil; [callTableView setAlpha:1.0]; [videoCameraSwitch setAlpha:1.0]; [UIView commitAnimations]; - + // hide controls in 5 sec hideControlsTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self @@ -321,15 +321,15 @@ static UICompositeViewDescription *compositeDescription = nil; [hideControlsTimer invalidate]; hideControlsTimer = nil; } - + if([[[PhoneMainView instance] currentView] equal:[InCallViewController compositeViewDescription]] && videoShown) { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.3]; [videoCameraSwitch setAlpha:0.0]; [callTableView setAlpha:0.0]; [UIView commitAnimations]; - - + + [[PhoneMainView instance] showTabBar: false]; [[PhoneMainView instance] showStateBar: false]; } @@ -351,19 +351,19 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)enableVideoDisplay:(BOOL)animation { if(videoShown && animation) return; - + videoShown = true; - + [videoZoomHandler resetZoom]; - + if(animation) { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; } - + [videoGroup setAlpha:1.0]; [callTableView setAlpha:0.0]; - + UIEdgeInsets insets = {33, 0, 25, 0}; [callTableView setContentInset:insets]; [callTableView setScrollIndicatorInsets:insets]; @@ -372,31 +372,31 @@ static UICompositeViewDescription *compositeDescription = nil; if(animation) { [UIView commitAnimations]; } - + if(linphone_core_self_view_enabled([LinphoneManager getLc])) { [videoPreview setHidden:FALSE]; } else { [videoPreview setHidden:TRUE]; } - + if ([LinphoneManager instance].frontCamId != nil) { // only show camera switch button if we have more than 1 camera [videoCameraSwitch setHidden:FALSE]; } [videoCameraSwitch setAlpha:0.0]; - + [[PhoneMainView instance] fullScreen: true]; [[PhoneMainView instance] showTabBar: false]; [[PhoneMainView instance] showStateBar: false]; - + #ifdef TEST_VIDEO_VIEW_CHANGE [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(_debugChangeVideoView) userInfo:nil repeats:YES]; #endif // [self batteryLevelChanged:nil]; - + [videoWaitingForFirstImage setHidden: NO]; [videoWaitingForFirstImage startAnimating]; - + LinphoneCall *call = linphone_core_get_current_call([LinphoneManager getLc]); //linphone_call_params_get_used_video_codec return 0 if no video stream enabled if (call != NULL && linphone_call_params_get_used_video_codec(linphone_call_get_current_params(call))) { @@ -407,13 +407,13 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)disableVideoDisplay:(BOOL)animation { if(!videoShown && animation) return; - + videoShown = false; if(animation) { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; } - + [videoGroup setAlpha:0.0]; [[PhoneMainView instance] showTabBar: true]; @@ -427,20 +427,20 @@ static UICompositeViewDescription *compositeDescription = nil; [callTableView setAlpha:1.0]; [videoCameraSwitch setHidden:TRUE]; - + if(animation) { [UIView commitAnimations]; } - + if (hideControlsTimer != nil) { [hideControlsTimer invalidate]; hideControlsTimer = nil; } - + [[PhoneMainView instance] fullScreen:false]; } -- (void)displayVideoCall:(BOOL)animated { +- (void)displayVideoCall:(BOOL)animated { [self enableVideoDisplay:animated]; } @@ -475,17 +475,17 @@ static void hideSpinner(LinphoneCall* call, void* user_data) { - (void)displayAskToEnableVideoCall:(LinphoneCall*) call { if (linphone_core_get_video_policy([LinphoneManager getLc])->automatically_accept) return; - + const char* lUserNameChars = linphone_address_get_username(linphone_call_get_remote_address(call)); NSString* lUserName = lUserNameChars?[[[NSString alloc] initWithUTF8String:lUserNameChars] autorelease]:NSLocalizedString(@"Unknown",nil); - const char* lDisplayNameChars = linphone_address_get_display_name(linphone_call_get_remote_address(call)); + const char* lDisplayNameChars = linphone_address_get_display_name(linphone_call_get_remote_address(call)); NSString* lDisplayName = [lDisplayNameChars?[[NSString alloc] initWithUTF8String:lDisplayNameChars]:@"" autorelease]; - + NSString* title = [NSString stringWithFormat : NSLocalizedString(@"'%@' would like to enable video",nil), ([lDisplayName length] > 0)?lDisplayName:lUserName]; DTActionSheet *sheet = [[[DTActionSheet alloc] initWithTitle:title] autorelease]; NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(dismissVideoActionSheet:) userInfo:sheet repeats:NO]; [sheet addButtonWithTitle:NSLocalizedString(@"Accept", nil) block:^() { - [LinphoneLogger logc:LinphoneLoggerLog format:"User accept video proposal"]; + LOGI(@"User accept video proposal"); LinphoneCallParams* paramsCopy = linphone_call_params_copy(linphone_call_get_current_params(call)); linphone_call_params_enable_video(paramsCopy, TRUE); linphone_core_accept_call_update([LinphoneManager getLc], call, paramsCopy); @@ -493,7 +493,7 @@ static void hideSpinner(LinphoneCall* call, void* user_data) { [timer invalidate]; }]; DTActionSheetBlock cancelBlock = ^() { - [LinphoneLogger logc:LinphoneLoggerLog format:"User declined video proposal"]; + LOGI(@"User declined video proposal"); LinphoneCallParams* paramsCopy = linphone_call_params_copy(linphone_call_get_current_params(call)); linphone_core_accept_call_update([LinphoneManager getLc], call, paramsCopy); linphone_call_params_destroy(paramsCopy); diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 2f9c9c371..b07aeacbd 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "PhoneMainView.h" #import "linphoneAppDelegate.h" @@ -49,7 +49,7 @@ } -#pragma mark - +#pragma mark - @@ -62,23 +62,23 @@ LOGI(@"%@", NSStringFromSelector(_cmd)); LinphoneCore* lc = [LinphoneManager getLc]; LinphoneCall* call = linphone_core_get_current_call(lc); - + if (call){ /* save call context */ LinphoneManager* instance = [LinphoneManager instance]; instance->currentCallContextBeforeGoingBackground.call = call; instance->currentCallContextBeforeGoingBackground.cameraIsEnabled = linphone_call_camera_enabled(call); - + const LinphoneCallParams* params = linphone_call_get_current_params(call); if (linphone_call_params_video_enabled(params)) { linphone_call_enable_camera(call, false); } } - + if (![[LinphoneManager instance] resignActive]) { } - + } - (void)applicationDidBecomeActive:(UIApplication *)application { @@ -90,12 +90,12 @@ [[PhoneMainView instance] updateStatusBar:nil]; } LinphoneManager* instance = [LinphoneManager instance]; - + [instance becomeActive]; - + LinphoneCore* lc = [LinphoneManager getLc]; LinphoneCall* call = linphone_core_get_current_call(lc); - + if (call){ if (call == instance->currentCallContextBeforeGoingBackground.call) { const LinphoneCallParams* params = linphone_call_get_current_params(call); @@ -115,23 +115,23 @@ } - (UIUserNotificationCategory*)getMessageNotificationCategory { - + UIMutableUserNotificationAction* reply = [[[UIMutableUserNotificationAction alloc] init] autorelease]; reply.identifier = @"reply"; reply.title = NSLocalizedString(@"Reply", nil); reply.activationMode = UIUserNotificationActivationModeForeground; reply.destructive = NO; reply.authenticationRequired = YES; - + UIMutableUserNotificationAction* mark_read = [[[UIMutableUserNotificationAction alloc] init] autorelease]; mark_read.identifier = @"mark_read"; mark_read.title = NSLocalizedString(@"Mark Read", nil); mark_read.activationMode = UIUserNotificationActivationModeBackground; mark_read.destructive = NO; mark_read.authenticationRequired = NO; - + NSArray* localRingActions = @[mark_read, reply]; - + UIMutableUserNotificationCategory* localRingNotifAction = [[[UIMutableUserNotificationCategory alloc] init] autorelease]; localRingNotifAction.identifier = @"incoming_msg"; [localRingNotifAction setActions:localRingActions forContext:UIUserNotificationActionContextDefault]; @@ -147,17 +147,17 @@ answer.activationMode = UIUserNotificationActivationModeForeground; answer.destructive = NO; answer.authenticationRequired = YES; - + UIMutableUserNotificationAction* decline = [[[UIMutableUserNotificationAction alloc] init] autorelease]; decline.identifier = @"decline"; decline.title = NSLocalizedString(@"Decline", nil); decline.activationMode = UIUserNotificationActivationModeBackground; decline.destructive = YES; decline.authenticationRequired = NO; - - + + NSArray* localRingActions = @[decline, answer]; - + UIMutableUserNotificationCategory* localRingNotifAction = [[[UIMutableUserNotificationCategory alloc] init] autorelease]; localRingNotifAction.identifier = @"incoming_call"; [localRingNotifAction setActions:localRingActions forContext:UIUserNotificationActionContextDefault]; @@ -176,13 +176,13 @@ LinphoneManager* instance = [LinphoneManager instance]; BOOL background_mode = [instance lpConfigBoolForKey:@"backgroundmode_preference"]; BOOL start_at_boot = [instance lpConfigBoolForKey:@"start_at_boot_preference"]; - - + + if( !instance.isTesting ){ if( [app respondsToSelector:@selector(registerUserNotificationSettings:)] ){ /* iOS8 notifications can be actioned! Awesome: */ UIUserNotificationType notifTypes = UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert; - + NSSet* categories = [NSSet setWithObjects:[self getCallNotificationCategory], [self getMessageNotificationCategory], nil]; UIUserNotificationSettings* userSettings = [UIUserNotificationSettings settingsForTypes:notifTypes categories:categories]; [app registerUserNotificationSettings:userSettings]; @@ -194,7 +194,7 @@ } else { NSLog(@"No remote push for testing"); } - + if (state == UIApplicationStateBackground) { @@ -208,7 +208,7 @@ } bgStartId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ - [LinphoneLogger log:LinphoneLoggerWarning format:@"Background task for application launching expired."]; + LOGW(@"Background task for application launching expired."); [[UIApplication sharedApplication] endBackgroundTask:bgStartId]; }]; @@ -223,7 +223,7 @@ NSDictionary *remoteNotif =[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (remoteNotif){ - [LinphoneLogger log:LinphoneLoggerLog format:@"PushNotification from launch received."]; + LOGI(@"PushNotification from launch received."); [self processRemoteNotification:remoteNotif]; } if (bgStartId!=UIBackgroundTaskInvalid) [[UIApplication sharedApplication] endBackgroundTask:bgStartId]; @@ -274,7 +274,7 @@ - (void)processRemoteNotification:(NSDictionary*)userInfo{ NSDictionary *aps = [userInfo objectForKey:@"aps"]; - + if(aps != nil) { NSDictionary *alert = [aps objectForKey:@"alert"]; if(alert != nil) { @@ -292,7 +292,7 @@ if( callId != nil ){ [[LinphoneManager instance] addPushCallId:callId]; } else { - [LinphoneLogger log:LinphoneLoggerError format:@"PushNotification: does not have call-id yet, fix it !"]; + LOGE(@"PushNotification: does not have call-id yet, fix it !"); } if( [loc_key isEqualToString:@"IM_MSG"] ) { @@ -414,7 +414,7 @@ if( [[UIDevice currentDevice].systemVersion floatValue] >= 8){ LinphoneCore* lc = [LinphoneManager getLc]; - [LinphoneLogger log:LinphoneLoggerLog format:@"%@", NSStringFromSelector(_cmd)]; + LOGI(@"%@", NSStringFromSelector(_cmd)); if( [notification.category isEqualToString:@"incoming_call"]) { if( [identifier isEqualToString:@"answer"] ){ // use the standard handler diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 16c3289ee..0f438ce9f 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -67,8 +67,8 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); bool_t value = linphone_core_payload_type_enabled(lc,pt); [self setBool:value forKey: pref]; }else{ - [LinphoneLogger logc:LinphoneLoggerWarning format:"Codec %s/%i supported by core is not shown in iOS app config view.", - pt->mime_type,pt->clock_rate]; + LOGW(@"Codec %s/%i supported by core is not shown in iOS app config view.", + pt->mime_type,pt->clock_rate); } } } @@ -186,7 +186,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); [self transformCodecsToKeys: linphone_core_get_video_codecs(lc)]; [self setBool:linphone_core_adaptive_rate_control_enabled(lc) forKey:@"adaptive_rate_control_preference"]; [self setString:linphone_core_get_adaptive_rate_algorithm(lc) forKey:@"adaptive_rate_algorithm_preference"]; - + [self setInteger:lp_config_get_int(conf, "audio", "codec_bitrate_limit", kLinphoneAudioVbrCodecDefaultBitrate) forKey:@"audio_codec_bitrate_limit_preference"]; [self setInteger:lp_config_get_int(conf, LINPHONERC_APPLICATION_KEY, "voiceproc_preference", 1) forKey:@"voiceproc_preference"]; [self setInteger:lp_config_get_int(conf, "sound", "eq_active", 0) forKey:@"eq_active"]; @@ -316,7 +316,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); // will also update the sip_*_port section of the config if (linphone_core_set_sip_transports(lc, &transportValue)) { - [LinphoneLogger logc:LinphoneLoggerError format:"cannot set transport"]; + LOGE(@"cannot set transport"); } port_preference = linphone_core_get_sip_port(lc); @@ -326,7 +326,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); BOOL enable_ipv6 = [self boolForKey:@"use_ipv6"]; lp_config_set_int(conf, "sip", "use_ipv6", enable_ipv6); if( linphone_core_ipv6_enabled(lc) != enable_ipv6){ - [LinphoneLogger logc:LinphoneLoggerDebug format:"%@ IPV6", enable_ipv6?@"ENABLING":@"DISABLING"]; + LOGD(@"%@ IPV6", enable_ipv6?@"ENABLING":@"DISABLING"); linphone_core_enable_ipv6(lc, enable_ipv6); } @@ -689,7 +689,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); BOOL debugmode = [self boolForKey:@"debugenable_preference"]; lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "debugenable_preference", debugmode); [[LinphoneManager instance] setLogsEnabled:debugmode]; - + BOOL animations = [self boolForKey:@"animations_preference"]; lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "animations_preference", animations); @@ -731,7 +731,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); } else if ([lTunnelPrefMode isEqualToString:@"auto"]) { mode = tunnel_auto; } else { - [LinphoneLogger logc:LinphoneLoggerError format:"Unexpected tunnel mode [%s]",[lTunnelPrefMode cStringUsingEncoding:[NSString defaultCStringEncoding]]]; + LOGE(@"Unexpected tunnel mode [%s]",[lTunnelPrefMode cStringUsingEncoding:[NSString defaultCStringEncoding]]); } } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 2fcd65cd3..ceb912e53 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -268,16 +268,16 @@ struct codec_name_pref_table codec_pref_table[]={ AudioSessionInitialize(NULL, NULL, NULL, NULL); OSStatus lStatus = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, audioRouteChangeListenerCallback, self); if (lStatus) { - [LinphoneLogger logc:LinphoneLoggerError format:"cannot register route change handler [%ld]",lStatus]; + LOGE(@"cannot register route change handler [%ld]",lStatus); } _iapManager = [[InAppProductsManager alloc] init]; - + NSString *path = [[NSBundle mainBundle] pathForResource:@"msg" ofType:@"wav"]; self.messagePlayer = [[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:path] error:nil] autorelease]; sounds.vibrate = kSystemSoundID_Vibrate; - + logs = [[NSMutableArray alloc] init]; database = NULL; speakerEnabled = FALSE; @@ -312,7 +312,7 @@ struct codec_name_pref_table codec_pref_table[]={ OSStatus lStatus = AudioSessionRemovePropertyListenerWithUserData(kAudioSessionProperty_AudioRouteChange, audioRouteChangeListenerCallback, self); if (lStatus) { - [LinphoneLogger logc:LinphoneLoggerError format:"cannot un register route change handler [%ld]", lStatus]; + LOGE(@"cannot un register route change handler [%ld]", lStatus); } [[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:kLinphoneGlobalStateUpdate]; @@ -327,7 +327,7 @@ struct codec_name_pref_table codec_pref_table[]={ - (void)silentPushFailed:(NSTimer*)timer { if( silentPushCompletion ){ - [LinphoneLogger log:LinphoneLoggerLog format:@"silentPush failed, silentPushCompletion block: %p", silentPushCompletion ]; + LOGI(@"silentPush failed, silentPushCompletion block: %p", silentPushCompletion ); silentPushCompletion(UIBackgroundFetchResultNoData); silentPushCompletion = nil; } @@ -357,7 +357,7 @@ static int check_should_migrate_images(void* data ,int argc,char** argv,char** c if( sqlite3_open([newDbPath UTF8String], &newDb) != SQLITE_OK) { - [LinphoneLogger log:LinphoneLoggerError format:@"Can't open \"%@\" sqlite3 database.", newDbPath]; + LOGE(@"Can't open \"%@\" sqlite3 database.", newDbPath); return FALSE; } @@ -370,14 +370,14 @@ static int check_should_migrate_images(void* data ,int argc,char** argv,char** c } - [LinphoneLogger logc:LinphoneLoggerLog format:"Starting migration procedure"]; + LOGI(@"Starting migration procedure"); if( shouldMigrate ){ // attach old database to the new one: attach_stmt = sqlite3_mprintf("ATTACH DATABASE %Q AS oldchats", [oldDbPath UTF8String]); if( sqlite3_exec(newDb, attach_stmt, NULL, NULL, &errMsg) != SQLITE_OK ){ - [LinphoneLogger logc:LinphoneLoggerError format:"Can't attach old chat table, error[%s] ", errMsg]; + LOGE(@"Can't attach old chat table, error[%s] ", errMsg); sqlite3_free(errMsg); goto exit_dbmigration; } @@ -388,7 +388,7 @@ static int check_should_migrate_images(void* data ,int argc,char** argv,char** c "SELECT localContact,remoteContact,direction,message,time,read,state,'-1' FROM oldchats.chat"; if( sqlite3_exec(newDb, migration_statement, NULL, NULL, &errMsg) != SQLITE_OK ){ - [LinphoneLogger logc:LinphoneLoggerError format:"DB migration failed, error[%s] ", errMsg]; + LOGE(@"DB migration failed, error[%s] ", errMsg); sqlite3_free(errMsg); goto exit_dbmigration; } @@ -396,7 +396,7 @@ static int check_should_migrate_images(void* data ,int argc,char** argv,char** c // invert direction of old messages, because iOS was storing the direction flag incorrectly const char* invert_direction = "UPDATE history SET direction = NOT direction"; if( sqlite3_exec(newDb, invert_direction, NULL, NULL, &errMsg) != SQLITE_OK){ - [LinphoneLogger log: LinphoneLoggerError format:@"Inverting direction failed, error[%s]", errMsg]; + LOGE(@"Inverting direction failed, error[%s]", errMsg); sqlite3_free(errMsg); goto exit_dbmigration; } @@ -411,14 +411,14 @@ static int check_should_migrate_images(void* data ,int argc,char** argv,char** c char* from_conversion = sqlite3_mprintf("UPDATE history SET localContact = %Q WHERE localContact = ''", identity); if( sqlite3_exec(newDb, from_conversion, NULL, NULL, &errMsg) != SQLITE_OK ){ - [LinphoneLogger logc:LinphoneLoggerError format:"FROM conversion failed, error[%s] ", errMsg]; + LOGE(@"FROM conversion failed, error[%s] ", errMsg); sqlite3_free(errMsg); } sqlite3_free(from_conversion); char* to_conversion = sqlite3_mprintf("UPDATE history SET remoteContact = %Q WHERE remoteContact = ''", identity); if( sqlite3_exec(newDb, to_conversion, NULL, NULL, &errMsg) != SQLITE_OK ){ - [LinphoneLogger logc:LinphoneLoggerError format:"DB migration failed, error[%s] ", errMsg]; + LOGE(@"DB migration failed, error[%s] ", errMsg); sqlite3_free(errMsg); } sqlite3_free(to_conversion); @@ -432,14 +432,14 @@ static int check_should_migrate_images(void* data ,int argc,char** argv,char** c // move already stored images from the messages to the appdata JSON field const char* assetslib_migration = "UPDATE history SET appdata='{\"localimage\":\"'||message||'\"}' , message='' WHERE message LIKE 'assets-library%'"; if( sqlite3_exec(newDb, assetslib_migration, NULL, NULL, &errMsg) != SQLITE_OK ){ - [LinphoneLogger logc:LinphoneLoggerError format:"Assets-history migration for MESSAGE failed, error[%s] ", errMsg]; + LOGE(@"Assets-history migration for MESSAGE failed, error[%s] ", errMsg); sqlite3_free(errMsg); } // move already stored images from the url to the appdata JSON field const char* assetslib_migration_fromurl = "UPDATE history SET appdata='{\"localimage\":\"'||url||'\"}' , url='' WHERE url LIKE 'assets-library%'"; if( sqlite3_exec(newDb, assetslib_migration_fromurl, NULL, NULL, &errMsg) != SQLITE_OK ){ - [LinphoneLogger logc:LinphoneLoggerError format:"Assets-history migration for URL failed, error[%s] ", errMsg]; + LOGE(@"Assets-history migration for URL failed, error[%s] ", errMsg); sqlite3_free(errMsg); } @@ -454,10 +454,10 @@ exit_dbmigration: // in any case, we should remove the old chat db if( shouldMigrate && ![[NSFileManager defaultManager] removeItemAtPath:oldDbPath error:&error] ){ - [LinphoneLogger logc:LinphoneLoggerError format:"Could not remove old chat DB: %@", error]; + LOGE(@"Could not remove old chat DB: %@", error); } - [LinphoneLogger log:LinphoneLoggerLog format:@"Message storage migration finished: success = %@", migrated ? @"TRUE":@"FALSE"]; + LOGI(@"Message storage migration finished: success = %@", migrated ? @"TRUE":@"FALSE"); return migrated; } @@ -524,11 +524,11 @@ struct _entry_data { static void dump_entry(const char* entry, void*data) { struct _entry_data *d = (struct _entry_data*)data; const char* value = lp_config_get_string(d->conf, d->section, entry, ""); - [LinphoneLogger log:LinphoneLoggerLog format:@"%s=%s", entry, value]; + LOGI(@"%s=%s", entry, value); } static void dump_section(const char* section, void* data){ - [LinphoneLogger log:LinphoneLoggerLog format:@"[%s]", section ]; + LOGI(@"[%s]", section ); struct _entry_data d = {(const LpConfig*)data, section}; lp_config_for_each_entry((const LpConfig*)data, section, dump_entry, &d); } @@ -604,7 +604,7 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char - (void)localNotifContinue:(NSTimer*) timer { UILocalNotification* notif = [timer userInfo]; if (notif){ - [LinphoneLogger log:LinphoneLoggerLog format:@"cancelling/presenting local notif"]; + LOGI(@"cancelling/presenting local notif"); [[UIApplication sharedApplication] cancelLocalNotification:notif]; [[UIApplication sharedApplication] presentLocalNotificationNow:notif]; } @@ -623,7 +623,7 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char // we were woken up by a silent push. Call the completion handler with NEWDATA // so that the push is notified to the user - [LinphoneLogger log:LinphoneLoggerLog format:@"onCall - handler %p", silentPushCompletion]; + LOGI(@"onCall - handler %p", silentPushCompletion); silentPushCompletion(UIBackgroundFetchResultNewData); silentPushCompletion = nil; } @@ -665,7 +665,7 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char if ([lCTCallCenter currentCalls]!=nil) { char *tmp=linphone_call_get_remote_address_as_string(call); if (tmp) { - [LinphoneLogger logc:LinphoneLoggerLog format:"Mobile call ongoing... rejecting call from [%s]",tmp]; + LOGI(@"Mobile call ongoing... rejecting call from [%s]",tmp); ms_free(tmp); } linphone_core_decline_call(theLinphoneCore, call,LinphoneReasonBusy); @@ -705,7 +705,7 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char if (!incallBgTask){ incallBgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^{ - [LinphoneLogger log:LinphoneLoggerWarning format:@"Call cannot ring any more, too late"]; + LOGW(@"Call cannot ring any more, too late"); [[UIApplication sharedApplication] endBackgroundTask:incallBgTask]; incallBgTask=0; }]; @@ -811,7 +811,7 @@ static void linphone_iphone_global_state_changed(LinphoneCore *lc, LinphoneGloba } -(void)onGlobalStateChanged:(LinphoneGlobalState)state withMessage:(const char*)message { - [LinphoneLogger log:LinphoneLoggerLog format:@"onGlobalStateChanged: %d (message: %s)", state, message]; + LOGI(@"onGlobalStateChanged: %d (message: %s)", state, message); NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:state], @"state", @@ -839,7 +839,7 @@ static void linphone_iphone_configuring_status_changed(LinphoneCore *lc, Linphon } -(void)onConfiguringStatusChanged:(LinphoneConfiguringState)status withMessage:(const char*)message { - [LinphoneLogger log:LinphoneLoggerLog format:@"onConfiguringStatusChanged: %d (message: %s)", status, message]; + LOGI(@"onConfiguringStatusChanged: %d (message: %s)", status, message); NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:status], @"state", @@ -865,7 +865,7 @@ static void linphone_iphone_configuring_status_changed(LinphoneCore *lc, Linphon #pragma mark - Registration State Functions - (void)onRegister:(LinphoneCore *)lc cfg:(LinphoneProxyConfig*) cfg state:(LinphoneRegistrationState) state message:(const char*) message { - [LinphoneLogger logc:LinphoneLoggerLog format:"NEW REGISTRATION STATE: '%s' (message: '%s')", linphone_registration_state_to_string(state), message]; + LOGI(@"NEW REGISTRATION STATE: '%s' (message: '%s')", linphone_registration_state_to_string(state), message); // Post event NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: @@ -889,7 +889,7 @@ static void linphone_iphone_registration_state(LinphoneCore *lc, LinphoneProxyCo // we were woken up by a silent push. Call the completion handler with NEWDATA // so that the push is notified to the user - [LinphoneLogger log:LinphoneLoggerLog format:@"onMessageReceived - handler %p", silentPushCompletion]; + LOGI(@"onMessageReceived - handler %p", silentPushCompletion); silentPushCompletion(UIBackgroundFetchResultNewData); silentPushCompletion = nil; } @@ -1046,7 +1046,7 @@ static void linphone_iphone_is_composing_received(LinphoneCore *lc, LinphoneChat NSString *data = nil; CFDictionaryRef dict = CNCopyCurrentNetworkInfo((CFStringRef)@"en0"); if(dict) { - [LinphoneLogger log:LinphoneLoggerDebug format:@"AP Wifi: %@", dict]; + LOGI(@"AP Wifi: %@", dict); data = [NSString stringWithString:(NSString*) CFDictionaryGetValue(dict, @"SSID")]; CFRelease(dict); } @@ -1055,24 +1055,25 @@ static void linphone_iphone_is_composing_received(LinphoneCore *lc, LinphoneChat } static void showNetworkFlags(SCNetworkReachabilityFlags flags){ - [LinphoneLogger logc:LinphoneLoggerLog format:"Network connection flags:"]; - if (flags==0) [LinphoneLogger logc:LinphoneLoggerLog format:"no flags."]; + LOGI(@"Network connection flags:"); + if (flags==0) + LOGI(@"no flags."); if (flags & kSCNetworkReachabilityFlagsTransientConnection) - [LinphoneLogger logc:LinphoneLoggerLog format:"kSCNetworkReachabilityFlagsTransientConnection"]; + LOGI(@"kSCNetworkReachabilityFlagsTransientConnection"); if (flags & kSCNetworkReachabilityFlagsReachable) - [LinphoneLogger logc:LinphoneLoggerLog format:"kSCNetworkReachabilityFlagsReachable"]; + LOGI(@"kSCNetworkReachabilityFlagsReachable"); if (flags & kSCNetworkReachabilityFlagsConnectionRequired) - [LinphoneLogger logc:LinphoneLoggerLog format:"kSCNetworkReachabilityFlagsConnectionRequired"]; + LOGI(@"kSCNetworkReachabilityFlagsConnectionRequired"); if (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) - [LinphoneLogger logc:LinphoneLoggerLog format:"kSCNetworkReachabilityFlagsConnectionOnTraffic"]; + LOGI(@"kSCNetworkReachabilityFlagsConnectionOnTraffic"); if (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) - [LinphoneLogger logc:LinphoneLoggerLog format:"kSCNetworkReachabilityFlagsConnectionOnDemand"]; + LOGI(@"kSCNetworkReachabilityFlagsConnectionOnDemand"); if (flags & kSCNetworkReachabilityFlagsIsLocalAddress) - [LinphoneLogger logc:LinphoneLoggerLog format:"kSCNetworkReachabilityFlagsIsLocalAddress"]; + LOGI(@"kSCNetworkReachabilityFlagsIsLocalAddress"); if (flags & kSCNetworkReachabilityFlagsIsDirect) - [LinphoneLogger logc:LinphoneLoggerLog format:"kSCNetworkReachabilityFlagsIsDirect"]; + LOGI(@"kSCNetworkReachabilityFlagsIsDirect"); if (flags & kSCNetworkReachabilityFlagsIsWWAN) - [LinphoneLogger logc:LinphoneLoggerLog format:"kSCNetworkReachabilityFlagsIsWWAN"]; + LOGI(@"kSCNetworkReachabilityFlagsIsWWAN"); } static void networkReachabilityNotification(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { @@ -1135,7 +1136,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach } linphone_core_set_network_reachable(theLinphoneCore,true); linphone_core_iterate(theLinphoneCore); - [LinphoneLogger logc:LinphoneLoggerLog format:"Network connectivity changed to type [%s]",(newConnectivity==wifi?"wifi":"wwan")]; + LOGI(@"Network connectivity changed to type [%s]",(newConnectivity==wifi?"wifi":"wwan")); } lLinphoneMgr.connectivity=newConnectivity; switch (lLinphoneMgr.tunnelMode) { @@ -1165,7 +1166,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach zeroAddress.sin_family = AF_INET; if (proxyReachability) { - [LinphoneLogger logc:LinphoneLoggerLog format:"Cancelling old network reachability"]; + LOGI(@"Cancelling old network reachability"); SCNetworkReachabilityUnscheduleFromRunLoop(proxyReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); CFRelease(proxyReachability); proxyReachability = nil; @@ -1190,14 +1191,14 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach proxyReachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zeroAddress); if (!SCNetworkReachabilitySetCallback(proxyReachability, (SCNetworkReachabilityCallBack)networkReachabilityCallBack, ctx)){ - [LinphoneLogger logc:LinphoneLoggerError format:"Cannot register reachability cb: %s", SCErrorString(SCError())]; + LOGE(@"Cannot register reachability cb: %s", SCErrorString(SCError())); return; } if(!SCNetworkReachabilityScheduleWithRunLoop(proxyReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)){ - [LinphoneLogger logc:LinphoneLoggerError format:"Cannot register schedule reachability cb: %s", SCErrorString(SCError())]; + LOGE(@"Cannot register schedule reachability cb: %s", SCErrorString(SCError())); return; } - + // this check is to know network connectivity right now without waiting for a change. Don'nt remove it unless you have good reason. Jehan SCNetworkReachabilityFlags flags; if (SCNetworkReachabilityGetFlags(proxyReachability, &flags)) { @@ -1343,7 +1344,7 @@ static LinphoneCoreVTable linphonec_vtable = { NSString* path = [LinphoneManager bundleFile:@"nowebcamCIF.jpg"]; if (path) { const char* imagePath = [path cStringUsingEncoding:[NSString defaultCStringEncoding]]; - [LinphoneLogger logc:LinphoneLoggerLog format:"Using '%s' as source image for no webcam", imagePath]; + LOGI(@"Using '%s' as source image for no webcam", imagePath); linphone_core_set_static_picture(theLinphoneCore, imagePath); } @@ -1366,12 +1367,12 @@ static LinphoneCoreVTable linphonec_vtable = { PayloadType *pt=linphone_core_find_payload_type(theLinphoneCore,"SILK",24000,-1); if (pt) { linphone_core_enable_payload_type(theLinphoneCore,pt,FALSE); - [LinphoneLogger logc:LinphoneLoggerWarning format:"SILK/24000 and video disabled on old iPhone 3G"]; + LOGW(@"SILK/24000 and video disabled on old iPhone 3G"); } linphone_core_enable_video(theLinphoneCore, FALSE, FALSE); } - [LinphoneLogger logc:LinphoneLoggerWarning format:"Linphone [%s] started on [%s]", linphone_core_get_version(), [[UIDevice currentDevice].model cStringUsingEncoding:[NSString defaultCStringEncoding]]]; + LOGW(@"Linphone [%s] started on [%s]", linphone_core_get_version(), [[UIDevice currentDevice].model cStringUsingEncoding:[NSString defaultCStringEncoding]]); // Post event @@ -1390,7 +1391,7 @@ static BOOL libStarted = FALSE; - (void)startLibLinphone { if ( libStarted ) { - [LinphoneLogger logc:LinphoneLoggerError format:"Liblinphone is already initialized!"]; + LOGE(@"Liblinphone is already initialized!"); return; } @@ -1432,10 +1433,10 @@ static BOOL libStarted = FALSE; - (void)createLinphoneCore { if (theLinphoneCore != nil) { - [LinphoneLogger logc:LinphoneLoggerLog format:"linphonecore is already created"]; + LOGI(@"linphonecore is already created"); return; } - [LinphoneLogger logc:LinphoneLoggerLog format:"Create linphonecore"]; + LOGI(@"Create linphonecore"); connectivity=none; @@ -1473,7 +1474,7 @@ static BOOL libStarted = FALSE; const char* lRootCa = [[LinphoneManager bundleFile:@"rootca.pem"] cStringUsingEncoding:[NSString defaultCStringEncoding]]; linphone_core_set_root_ca(theLinphoneCore, lRootCa); linphone_core_set_user_certificates_path(theLinphoneCore,[[LinphoneManager cacheDirectory] UTF8String]); - + /* The core will call the linphone_iphone_configuring_status_changed callback when the remote provisioning is loaded (or skipped). Wait for this to finish the code configuration */ @@ -1499,7 +1500,7 @@ static BOOL libStarted = FALSE; [[NSNotificationCenter defaultCenter] removeObserver:self]; if (theLinphoneCore != nil) { //just in case application terminate before linphone core initialization - [LinphoneLogger logc:LinphoneLoggerLog format:"Destroy linphonecore"]; + LOGI(@"Destroy linphonecore"); linphone_core_destroy(theLinphoneCore); theLinphoneCore = nil; ms_exit(); // Uninitialize mediastreamer2 @@ -1599,11 +1600,11 @@ static int comp_call_state_paused (const LinphoneCall* call, const void* param) - (void) startCallPausedLongRunningTask { pausedCallBgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^{ - [LinphoneLogger log:LinphoneLoggerWarning format:@"Call cannot be paused any more, too late"]; + LOGW(@"Call cannot be paused any more, too late"); [[UIApplication sharedApplication] endBackgroundTask:pausedCallBgTask]; }]; - [LinphoneLogger log:LinphoneLoggerLog format:@"Long running task started, remaining [%g s] because at least one call is paused" - ,[[UIApplication sharedApplication] backgroundTimeRemaining]]; + LOGI(@"Long running task started, remaining [%g s] because at least one call is paused" + ,[[UIApplication sharedApplication] backgroundTimeRemaining]); } - (BOOL)enterBackgroundMode { LinphoneProxyConfig* proxyCfg; @@ -1624,13 +1625,13 @@ static int comp_call_state_paused (const LinphoneCall* call, const void* param) //register keepalive if ([[UIApplication sharedApplication] setKeepAliveTimeout:600/*(NSTimeInterval)linphone_proxy_config_get_expires(proxyCfg)*/ handler:^{ - [LinphoneLogger logc:LinphoneLoggerWarning format:"keepalive handler"]; + LOGW(@"keepalive handler"); if (mLastKeepAliveDate) [mLastKeepAliveDate release]; mLastKeepAliveDate=[NSDate date]; [mLastKeepAliveDate retain]; if (theLinphoneCore == nil) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"It seems that Linphone BG mode was deactivated, just skipping"]; + LOGW(@"It seems that Linphone BG mode was deactivated, just skipping"); return; } //kick up network cnx, just in case @@ -1640,9 +1641,9 @@ static int comp_call_state_paused (const LinphoneCall* call, const void* param) ]) { - [LinphoneLogger logc:LinphoneLoggerLog format:"keepalive handler succesfully registered"]; + LOGI(@"keepalive handler succesfully registered"); } else { - [LinphoneLogger logc:LinphoneLoggerLog format:"keepalive handler cannot be registered"]; + LOGI(@"keepalive handler cannot be registered"); } shouldEnterBgMode=TRUE; } @@ -1666,11 +1667,11 @@ static int comp_call_state_paused (const LinphoneCall* call, const void* param) } linphone_core_stop_dtmf_stream(theLinphoneCore); - [LinphoneLogger logc:LinphoneLoggerLog format:"Entering [%s] bg mode",shouldEnterBgMode?"normal":"lite"]; + LOGI(@"Entering [%s] bg mode",shouldEnterBgMode?"normal":"lite"); if (!shouldEnterBgMode ) { if([[LinphoneManager instance] lpConfigBoolForKey:@"pushnotification_preference"]) { - [LinphoneLogger logc:LinphoneLoggerLog format:"Keeping lc core to handle push"]; + LOGI(@"Keeping lc core to handle push"); /*destroy voip socket if any and reset connectivity mode*/ connectivity=none; linphone_core_set_network_reachable(theLinphoneCore, FALSE); @@ -1705,7 +1706,7 @@ static int comp_call_state_paused (const LinphoneCall* call, const void* param) NSDate *current=[NSDate date]; if ([current timeIntervalSinceDate:mLastKeepAliveDate]>700){ NSString *datestr=[mLastKeepAliveDate description]; - [LinphoneLogger logc:LinphoneLoggerWarning format:"keepalive handler was called for the last time at %@",datestr]; + LOGW(@"keepalive handler was called for the last time at %@",datestr); } } @@ -1713,14 +1714,14 @@ static int comp_call_state_paused (const LinphoneCall* call, const void* param) - (void)beginInterruption { LinphoneCall* c = linphone_core_get_current_call(theLinphoneCore); - [LinphoneLogger logc:LinphoneLoggerLog format:"Sound interruption detected!"]; + LOGI(@"Sound interruption detected!"); if (c && linphone_call_get_state(c) == LinphoneCallStreamsRunning) { linphone_core_pause_call(theLinphoneCore, c); } } - (void)endInterruption { - [LinphoneLogger logc:LinphoneLoggerLog format:"Sound interruption ended!"]; + LOGI(@"Sound interruption ended!"); } - (void)refreshRegisters{ @@ -1774,7 +1775,7 @@ static void audioRouteChangeListenerCallback ( OSStatus lStatus = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &lNewRouteSize, &lNewRoute); if (!lStatus && lNewRouteSize > 0) { NSString *route = (NSString *) lNewRoute; - [LinphoneLogger logc:LinphoneLoggerLog format:"Current audio route is [%s]", [route cStringUsingEncoding:[NSString defaultCStringEncoding]]]; + LOGI(@"Current audio route is [%s]", [route cStringUsingEncoding:[NSString defaultCStringEncoding]]); speakerEnabled = [route isEqualToString: @"Speaker"] || [route isEqualToString: @"SpeakerAndMicrophone"]; @@ -1836,7 +1837,7 @@ static void audioRouteChangeListenerCallback ( if([self lpConfigBoolForKey:@"edge_opt_preference"]) { bool low_bandwidth = self.network == network_2g; if(low_bandwidth) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Low bandwidth mode"]; + LOGI(@"Low bandwidth mode"); } linphone_call_params_enable_low_bandwidth(lcallParams, low_bandwidth); } @@ -1858,7 +1859,7 @@ static void audioRouteChangeListenerCallback ( CTCallCenter* callCenter = [[CTCallCenter alloc] init]; if ([callCenter currentCalls]!=nil) { - [LinphoneLogger logc:LinphoneLoggerError format:"GSM call in progress, cancelling outgoing SIP call request"]; + LOGE(@"GSM call in progress, cancelling outgoing SIP call request"); UIAlertView* error = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Cannot make call",nil) message:NSLocalizedString(@"Please terminate GSM call",nil) delegate:nil @@ -1878,7 +1879,7 @@ static void audioRouteChangeListenerCallback ( if([self lpConfigBoolForKey:@"edge_opt_preference"]) { bool low_bandwidth = self.network == network_2g; if(low_bandwidth) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Low bandwidth mode"]; + LOGI(@"Low bandwidth mode"); } linphone_call_params_enable_low_bandwidth(lcallParams, low_bandwidth); } @@ -1929,10 +1930,10 @@ static void audioRouteChangeListenerCallback ( if (call) { // The LinphoneCallAppData object should be set on call creation with callback // - (void)onCall:StateChanged:withMessage:. If not, we are in big trouble and expect it to crash - // We are NOT responsible for creating the AppData. + // We are NOT responsible for creating the AppData. LinphoneCallAppData* data=(LinphoneCallAppData*)linphone_call_get_user_pointer(call); if (data==nil) - [LinphoneLogger log:LinphoneLoggerError format:@"New call instanciated but app data was not set. Expect it to crash."]; + LOGE(@"New call instanciated but app data was not set. Expect it to crash."); /* will be used later to notify user if video was not activated because of the linphone core*/ data->videoRequested = linphone_call_params_video_enabled(lcallParams); } @@ -2037,21 +2038,21 @@ static void audioRouteChangeListenerCallback ( if(override) { [fileManager removeItemAtPath:dst error:&error]; if(error != nil) { - [LinphoneLogger log:LinphoneLoggerError format:@"Can't remove \"%@\": %@", dst, [error localizedDescription]]; + LOGE(@"Can't remove \"%@\": %@", dst, [error localizedDescription]); return FALSE; } } else { - [LinphoneLogger log:LinphoneLoggerWarning format:@"\"%@\" already exists", dst]; + LOGW(@"\"%@\" already exists", dst); return FALSE; } } if ([fileManager fileExistsAtPath:src] == NO) { - [LinphoneLogger log:LinphoneLoggerError format:@"Can't find \"%@\": %@", src, [error localizedDescription]]; + LOGE(@"Can't find \"%@\": %@", src, [error localizedDescription]); return FALSE; } [fileManager copyItemAtPath:src toPath:dst error:&error]; if(error != nil) { - [LinphoneLogger log:LinphoneLoggerError format:@"Can't copy \"%@\" to \"%@\": %@", src, dst, [error localizedDescription]]; + LOGE(@"Can't copy \"%@\" to \"%@\": %@", src, dst, [error localizedDescription]); return FALSE; } return TRUE; @@ -2180,7 +2181,7 @@ static void audioRouteChangeListenerCallback ( -(void) removeCTCallCenterCb { if (mCallCenter != nil) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Removing CT call center listener [%p]",mCallCenter]; + LOGI(@"Removing CT call center listener [%p]",mCallCenter); mCallCenter.callEventHandler=NULL; [mCallCenter release]; } @@ -2191,7 +2192,7 @@ static void audioRouteChangeListenerCallback ( [self removeCTCallCenterCb]; mCallCenter = [[CTCallCenter alloc] init]; - [LinphoneLogger log:LinphoneLoggerLog format:@"Adding CT call center listener [%p]",mCallCenter]; + LOGI(@"Adding CT call center listener [%p]",mCallCenter); mCallCenter.callEventHandler = ^(CTCall* call) { // post on main thread [self performSelectorOnMainThread:@selector(handleGSMCallInteration:) @@ -2207,11 +2208,11 @@ static void audioRouteChangeListenerCallback ( LinphoneCall* call = linphone_core_get_current_call(theLinphoneCore); if ([ct currentCalls]!=nil) { if (call) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Pausing SIP call because GSM call"]; + LOGI(@"Pausing SIP call because GSM call"); linphone_core_pause_call(theLinphoneCore, call); [self startCallPausedLongRunningTask]; } else if (linphone_core_is_in_conference(theLinphoneCore)) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Leaving conference call because GSM call"]; + LOGI(@"Leaving conference call because GSM call"); linphone_core_leave_conference(theLinphoneCore); [self startCallPausedLongRunningTask]; } diff --git a/Classes/LinphoneUI/UIBluetoothButton.m b/Classes/LinphoneUI/UIBluetoothButton.m index 6c3ee43f3..b5c3d35a5 100644 --- a/Classes/LinphoneUI/UIBluetoothButton.m +++ b/Classes/LinphoneUI/UIBluetoothButton.m @@ -25,7 +25,7 @@ @implementation UIBluetoothButton #define check_auresult(au,method) \ -if (au!=0) [LinphoneLogger logc:LinphoneLoggerError format:"UIBluetoothButton error for %s: ret=%ld",method,au] +if (au!=0) LOGE(@"UIBluetoothButton error for %s: ret=%ld",method,au) - (void)onOn { //redirect audio to bluetooth diff --git a/Classes/LinphoneUI/UICallCell.m b/Classes/LinphoneUI/UICallCell.m index 894cf1a27..25f9145e2 100644 --- a/Classes/LinphoneUI/UICallCell.m +++ b/Classes/LinphoneUI/UICallCell.m @@ -44,7 +44,7 @@ - (void)update { if(call == NULL) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update call cell: null call or data"]; + LOGW(@"Cannot update call cell: null call or data"); return; } const LinphoneAddress* addr = linphone_call_get_remote_address(call); @@ -377,7 +377,7 @@ - (void)update { if(data == nil || data->call == NULL) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update call cell: null call or data"]; + LOGW(@"Cannot update call cell: null call or data"); return; } LinphoneCall *call = data->call; @@ -442,7 +442,7 @@ - (void)updateStats { if(data == nil || data->call == NULL) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update call cell: null call or data"]; + LOGW(@"Cannot update call cell: null call or data"); return; } LinphoneCall *call = data->call; @@ -500,7 +500,7 @@ - (void)updateDetailsView { if(data == nil || data->call == NULL) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update call cell: null call or data"]; + LOGW(@"Cannot update call cell: null call or data"); return; } if(data->view == UICallCellOtherView_Avatar && avatarView.isHidden) { diff --git a/Classes/LinphoneUI/UICamSwitch.m b/Classes/LinphoneUI/UICamSwitch.m index cc5bcab87..a3709596f 100644 --- a/Classes/LinphoneUI/UICamSwitch.m +++ b/Classes/LinphoneUI/UICamSwitch.m @@ -79,7 +79,7 @@ } } if (newCamId){ - [LinphoneLogger logc:LinphoneLoggerLog format:"Switching from [%s] to [%s]", currentCamId, newCamId]; + LOGI(@"Switching from [%s] to [%s]", currentCamId, newCamId); linphone_core_set_video_device([LinphoneManager getLc], newCamId); LinphoneCall *call = linphone_core_get_current_call([LinphoneManager getLc]); if(call != NULL) { diff --git a/Classes/LinphoneUI/UIChatCell.m b/Classes/LinphoneUI/UIChatCell.m index 5fcf753ad..23fe84382 100644 --- a/Classes/LinphoneUI/UIChatCell.m +++ b/Classes/LinphoneUI/UIChatCell.m @@ -4,16 +4,16 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -39,9 +39,9 @@ NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"UIChatCell" owner:self options:nil]; - + if ([arrayOfViews count] >= 1) { - + [self.contentView addSubview:[arrayOfViews objectAtIndex:0]]; } [chatContentLabel setAdjustsFontSizeToFitWidth:TRUE]; // Auto shrink: IB lack! @@ -69,7 +69,7 @@ } -#pragma mark - +#pragma mark - - (NSString *)accessibilityValue { return [NSString stringWithFormat:@"%@ - %@ (%ld)", addressLabel.text, chatContentLabel.text, (long)[unreadMessageLabel.text integerValue]]; @@ -80,7 +80,7 @@ NSString *displayName = nil; UIImage *image = nil; if(chatRoom == nil) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update chat cell: null chat"]; + LOGW(@"Cannot update chat cell: null chat"); return; } const LinphoneAddress* linphoneAddress = linphone_chat_room_get_peer_address(chatRoom); @@ -90,13 +90,13 @@ char *tmp = linphone_address_as_string_uri_only(linphoneAddress); NSString *normalizedSipAddress = [NSString stringWithUTF8String:tmp]; ms_free(tmp); - + ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:normalizedSipAddress]; if(contact != nil) { displayName = [FastAddressBook getContactDisplayName:contact]; image = [FastAddressBook getContactImage:contact thumbnail:true]; } - + // Display name if(displayName == nil) { const char* username = linphone_address_get_username(linphoneAddress); @@ -156,7 +156,7 @@ if(editing) { [deleteButton setAlpha:1.0f]; } else { - [deleteButton setAlpha:0.0f]; + [deleteButton setAlpha:0.0f]; } if(animated) { [UIView commitAnimations]; @@ -168,7 +168,7 @@ - (IBAction)onDeleteClick: (id) event { if(chatRoom != NULL) { - UIView *view = [self superview]; + UIView *view = [self superview]; // Find TableViewCell while( view != nil && ![view isKindOfClass:[UITableView class]]) view = [view superview]; if(view != nil) { diff --git a/Classes/LinphoneUI/UIChatRoomCell.m b/Classes/LinphoneUI/UIChatRoomCell.m index 2ffa9a7e2..f877557ad 100644 --- a/Classes/LinphoneUI/UIChatRoomCell.m +++ b/Classes/LinphoneUI/UIChatRoomCell.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "UIChatRoomCell.h" #import "UILinphone.h" @@ -68,7 +68,7 @@ static UIFont *CELL_FONT = nil; [self addSubview:innerView]; [deleteButton setAlpha:0.0f]; - + // shift message box, otherwise it will collide with the bubble CGRect messageCoords = [messageText frame]; messageCoords.origin.x += 2; @@ -93,16 +93,16 @@ static UIFont *CELL_FONT = nil; [downloadButton release]; [imageTapGestureRecognizer release]; [resendTapGestureRecognizer release]; - + [super dealloc]; } -#pragma mark - +#pragma mark - - (void)setChatMessage:(LinphoneChatMessage *)message { self->chat = message; [self update]; - + } + (NSString*)decodeTextMessage:(const char*)text { @@ -119,7 +119,7 @@ static UIFont *CELL_FONT = nil; - (void)update { if(chat == nil) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update chat room cell: null chat"]; + LOGW(@"Cannot update chat room cell: null chat"); return; } const char* url = linphone_chat_message_get_external_body_url(chat); @@ -155,9 +155,9 @@ static UIFont *CELL_FONT = nil; } }); } failureBlock:^(NSError *error) { - [LinphoneLogger log:LinphoneLoggerError format:@"Can't read image"]; + LOGE(@"Can't read image"); }]; - + [messageImageView setHidden:FALSE]; [downloadButton setHidden:TRUE]; } else { @@ -182,10 +182,10 @@ static UIFont *CELL_FONT = nil; [messageImageView setImage:nil]; [messageImageView setHidden:TRUE]; - + [downloadButton setHidden:TRUE]; } - + // Date NSDate* message_date = [NSDate dateWithTimeIntervalSince1970:linphone_chat_message_get_time(chat)]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; @@ -220,13 +220,13 @@ static UIFont *CELL_FONT = nil; [dateLabel setAttributedText:resend_text]; [resend_text release]; } - + if( outgoing){ [messageText setAccessibilityLabel:@"Outgoing message"]; } else { [messageText setAccessibilityLabel:@"Incoming message"]; } - + } - (void)setEditing:(BOOL)editing { @@ -241,7 +241,7 @@ static UIFont *CELL_FONT = nil; if(editing) { [deleteButton setAlpha:1.0f]; } else { - [deleteButton setAlpha:0.0f]; + [deleteButton setAlpha:0.0f]; } if(animated) { [UIView commitAnimations]; @@ -330,7 +330,7 @@ static UIFont *CELL_FONT = nil; - (IBAction)onDeleteClick:(id)event { if(chat != NULL) { - UIView *view = [self superview]; + UIView *view = [self superview]; // Find TableViewCell while(view != nil && ![view isKindOfClass:[UITableView class]]) view = [view superview]; if(view != nil) { diff --git a/Classes/LinphoneUI/UICompositeViewController.m b/Classes/LinphoneUI/UICompositeViewController.m index 0cdafc3b1..da3230d31 100644 --- a/Classes/LinphoneUI/UICompositeViewController.m +++ b/Classes/LinphoneUI/UICompositeViewController.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "UICompositeViewController.h" @@ -52,8 +52,8 @@ return [self.name compare:description.name] == NSOrderedSame; } -- (id)init:(NSString *)aname content:(NSString *)acontent stateBar:(NSString*)astateBar - stateBarEnabled:(BOOL) astateBarEnabled +- (id)init:(NSString *)aname content:(NSString *)acontent stateBar:(NSString*)astateBar + stateBarEnabled:(BOOL) astateBarEnabled tabBar:(NSString*)atabBar tabBarEnabled:(BOOL) atabBarEnabled fullscreen:(BOOL) afullscreen @@ -69,7 +69,7 @@ self.landscapeMode = alandscapeMode; self.portraitMode = aportraitMode; self.darkBackground = false; - + return self; } @@ -131,22 +131,22 @@ [self initUICompositeViewController]; } return self; -} +} - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; - + [self.stateBarViewController release]; [self.tabBarViewController release]; [self.contentViewController release]; - + [contentView release]; [stateBarView release]; [tabBarView release]; [viewControllerCache release]; [viewTransition release]; [currentViewDescription release]; - + [super dealloc]; } @@ -190,7 +190,7 @@ } - (void)viewDidLoad { - /* Force landscape view to match portrait view, because portrait view inherits + /* Force landscape view to match portrait view, because portrait view inherits the device screen size at load */ [self updateViewsFramesAccordingToLaunchOrientation]; [super viewDidLoad]; @@ -201,7 +201,7 @@ [self.contentViewController viewWillAppear:animated]; [self.tabBarViewController viewWillAppear:animated]; [self.stateBarViewController viewWillAppear:animated]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification @@ -221,9 +221,9 @@ [self.contentViewController viewWillDisappear:animated]; [self.tabBarViewController viewWillDisappear:animated]; [self.stateBarViewController viewWillDisappear:animated]; - + [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; - + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; @@ -340,7 +340,7 @@ } } if(remove) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Free cached view: %@", key]; + LOGI(@"Free cached view: %@", key); [viewControllerCache removeObjectForKey:key]; } } @@ -420,7 +420,7 @@ if(description != nil) { oldViewDescription = currentViewDescription; currentViewDescription = [description copy]; - + // Animate only with a previous screen if(oldViewDescription != nil && viewTransition != nil) { [contentView.layer removeAnimationForKey:@"transition"]; @@ -454,7 +454,7 @@ self.stateBarViewController = newStateBarViewController; self.contentViewController = newContentViewController; self.tabBarViewController = newTabBarViewController; - + // Update rotation UIInterfaceOrientation correctOrientation = [self getCorrectInterfaceOrientation:(UIDeviceOrientation)[UIApplication sharedApplication].statusBarOrientation]; if(currentOrientation != correctOrientation) { @@ -487,11 +487,11 @@ } else { oldViewDescription = (currentViewDescription != nil)? [currentViewDescription copy]: nil; } - + if(currentViewDescription == nil) { return; } - + if(tabBar != nil) { if(currentViewDescription.tabBarEnabled != [tabBar boolValue]) { currentViewDescription.tabBarEnabled = [tabBar boolValue]; @@ -499,7 +499,7 @@ tabBar = nil; // No change = No Update } } - + if(stateBar != nil) { if(currentViewDescription.stateBarEnabled != [stateBar boolValue]) { currentViewDescription.stateBarEnabled = [stateBar boolValue]; @@ -507,7 +507,7 @@ stateBar = nil; // No change = No Update } } - + if(fullscreen != nil) { if(currentViewDescription.fullscreen != [fullscreen boolValue]) { currentViewDescription.fullscreen = [fullscreen boolValue]; @@ -518,23 +518,23 @@ } else { [[UIApplication sharedApplication] setStatusBarHidden:currentViewDescription.fullscreen withAnimation:UIStatusBarAnimationNone]; } - + // Start animation if(tabBar != nil || stateBar != nil || fullscreen != nil) { [UIView beginAnimations:@"resize" context:nil]; [UIView setAnimationDuration:0.35]; [UIView setAnimationBeginsFromCurrentState:TRUE]; } - + CGRect contentFrame = contentView.frame; CGRect viewFrame = [self.view frame]; - + // Resize StateBar CGRect stateBarFrame = stateBarView.frame; int origin = IPHONE_STATUSBAR_HEIGHT; if(currentViewDescription.fullscreen) origin = 0; - + if(self.stateBarViewController != nil && currentViewDescription.stateBarEnabled) { contentFrame.origin.y = origin + stateBarFrame.size.height; stateBarFrame.origin.y = origin; @@ -542,7 +542,7 @@ contentFrame.origin.y = origin; stateBarFrame.origin.y = origin - stateBarFrame.size.height; } - + // Resize TabBar CGRect tabFrame = tabBarView.frame; if(self.tabBarViewController != nil && currentViewDescription.tabBarEnabled) { @@ -567,12 +567,12 @@ contentFrame.size.height = viewFrame.size.height - contentFrame.origin.y; tabFrame.origin.y = viewFrame.size.height; } - + if(currentViewDescription.fullscreen) { contentFrame.origin.y = origin; contentFrame.size.height = viewFrame.size.height - contentFrame.origin.y; } - + // Set frames [contentView setFrame: contentFrame]; [self.contentViewController.view setFrame: [contentView bounds]]; @@ -584,12 +584,12 @@ frame = [self.stateBarViewController.view frame]; frame.size.width = [stateBarView bounds].size.width; [self.stateBarViewController.view setFrame:frame]; - + // Commit animation if(tabBar != nil || stateBar != nil || fullscreen != nil) { [UIView commitAnimations]; } - + // Change view if(description != nil) { [UICompositeViewController addSubView: self.contentViewController view:contentView]; @@ -600,7 +600,7 @@ [UICompositeViewController addSubView: self.stateBarViewController view:stateBarView]; } } - + // Dealloc old view description if(oldViewDescription != nil) { [oldViewDescription release]; diff --git a/Classes/LinphoneUI/UIContactCell.m b/Classes/LinphoneUI/UIContactCell.m index 5f3c595de..ad0945609 100644 --- a/Classes/LinphoneUI/UIContactCell.m +++ b/Classes/LinphoneUI/UIContactCell.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "UIContactCell.h" #import "Utils.h" @@ -36,7 +36,7 @@ NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"UIContactCell" owner:self options:nil]; - + if ([arrayOfViews count] >= 1) { [self.contentView addSubview:[arrayOfViews objectAtIndex:0] ]; } @@ -48,7 +48,7 @@ [firstNameLabel release]; [lastNameLabel release]; [avatarImage release]; - + [super dealloc]; } @@ -60,7 +60,7 @@ [self update]; } -#pragma mark - +#pragma mark - - (void)touchUp:(id) sender { [self setHighlighted:true animated:true]; @@ -76,10 +76,10 @@ - (void)update { if(contact == NULL) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update contact cell: null contact"]; + LOGW(@"Cannot update contact cell: null contact"); return; } - + CFStringRef lFirstName = ABRecordCopyValue(contact, kABPersonFirstNameProperty); CFStringRef lLocalizedFirstName = (lFirstName != nil)?ABAddressBookCopyLocalizedLabel(lFirstName):nil; CFStringRef lLastName = ABRecordCopyValue(contact, kABPersonLastNameProperty); @@ -92,17 +92,17 @@ } else [firstNameLabel setText: @""]; - + if(lLocalizedLastName != nil){ [lastNameLabel setText: (NSString *)lLocalizedLastName]; } else [lastNameLabel setText: @""]; - + if(lLocalizedFirstName == nil && lLocalizedLastName == nil) { [firstNameLabel setText: (NSString *)lLocalizedOrganization]; } - + if(lLocalizedOrganization != nil) CFRelease(lLocalizedOrganization); if(lOrganization != nil) @@ -124,7 +124,7 @@ // CGRect firstNameFrame = [firstNameLabel frame]; CGRect lastNameFrame = [lastNameLabel frame]; - + // Compute firstName size CGSize firstNameSize = [[firstNameLabel text] sizeWithFont:[firstNameLabel font]]; CGSize lastNameSize = [[lastNameLabel text] sizeWithFont:[lastNameLabel font]]; @@ -134,10 +134,10 @@ firstNameSize.width *= limit/sum; lastNameSize.width *= limit/sum; } - + firstNameFrame.size.width = firstNameSize.width; lastNameFrame.size.width = lastNameSize.width; - + // Compute lastName size & position lastNameFrame.origin.x = firstNameFrame.origin.x + firstNameFrame.size.width; if(firstNameFrame.size.width) @@ -158,7 +158,7 @@ [firstNameLabel setTextColor:[UIColor whiteColor]]; } else { [lastNameLabel setTextColor:[UIColor blackColor]]; - [firstNameLabel setTextColor:[UIColor blackColor]]; + [firstNameLabel setTextColor:[UIColor blackColor]]; } } diff --git a/Classes/LinphoneUI/UIContactDetailsHeader.m b/Classes/LinphoneUI/UIContactDetailsHeader.m index 376006b15..3d9d9b331 100644 --- a/Classes/LinphoneUI/UIContactDetailsHeader.m +++ b/Classes/LinphoneUI/UIContactDetailsHeader.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "UIContactDetailsHeader.h" #import "Utils.h" @@ -78,9 +78,9 @@ [normalView release]; [editView release]; [tableView release]; - + [propertyList release]; - + [super dealloc]; } @@ -119,10 +119,10 @@ - (void)update { if(contact == NULL) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update contact details header: null contact"]; + LOGW(@"Cannot update contact details header: null contact"); return; } - + // Avatar image { UIImage *image = [FastAddressBook getContactImage:contact thumbnail:false]; @@ -131,12 +131,12 @@ } [avatarImage setImage:image]; } - + // Contact label { [addressLabel setText:[FastAddressBook getContactDisplayName:contact]]; } - + [tableView reloadData]; } @@ -154,7 +154,7 @@ if(!editing) { [LinphoneUtils findAndResignFirstResponder:[self tableView]]; [self update]; - } + } if(animated) { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.3]; @@ -164,7 +164,7 @@ [normalView setAlpha:0.0f]; } else { [editView setAlpha:0.0f]; - [normalView setAlpha:1.0f]; + [normalView setAlpha:1.0f]; } if(animated) { [UIView commitAnimations]; @@ -203,7 +203,7 @@ - (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *kCellId = @"ContactDetailsHeaderCell"; UIEditableTableViewCell *cell = [atableView dequeueReusableCellWithIdentifier:kCellId]; - if (cell == nil) { + if (cell == nil) { cell = [[[UIEditableTableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:kCellId] autorelease]; [cell.detailTextField setAutocapitalizationType:UITextAutocapitalizationTypeWords]; [cell.detailTextField setAutocorrectionType:UITextAutocorrectionTypeNo]; @@ -236,7 +236,7 @@ } } [cell.detailTextField setDelegate:self]; - + return cell; } @@ -257,16 +257,16 @@ } if(controller != nil) { controller.sourceType = type; - + // Displays a control that allows the user to choose picture or // movie capture, if both are available: controller.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage]; - + // Hides the controls for moving & scaling pictures, or for // trimming movies. To instead show the controls, use YES. controller.allowsEditing = NO; controller.imagePickerDelegate = self; - + if([LinphoneManager runningOnIpad]) { [controller.popoverController presentPopoverFromRect:[avatarImage frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:FALSE]; } @@ -287,7 +287,7 @@ [sheet addDestructiveButtonWithTitle:NSLocalizedString(@"Remove", nil) block:^(){ NSError* error = NULL; if(!ABPersonRemoveImageData(contact, (CFErrorRef*)error)) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Can't remove entry: %@", [error localizedDescription]]; + LOGI(@"Can't remove entry: %@", [error localizedDescription]); } [self update]; }]; @@ -316,7 +316,7 @@ FastAddressBook* fab = [LinphoneManager instance].fastAddressBook; NSError* error = NULL; if(!ABPersonRemoveImageData(contact, (CFErrorRef*)error)) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Can't remove entry: %@", [error localizedDescription]]; + LOGI(@"Can't remove entry: %@", [error localizedDescription]); } NSData *dataRef = UIImageJPEGRepresentation(image, 0.9f); CFDataRef cfdata = CFDataCreate(NULL,[dataRef bytes], [dataRef length]); @@ -324,13 +324,13 @@ [fab saveAddressBook]; if(!ABPersonSetImageData(contact, cfdata, (CFErrorRef*)error)) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Can't add entry: %@", [error localizedDescription]]; + LOGI(@"Can't add entry: %@", [error localizedDescription]); } else { [fab saveAddressBook]; } CFRelease(cfdata); - + [self update]; } @@ -345,7 +345,7 @@ #pragma mark - UITextFieldDelegate Functions - (BOOL)textFieldShouldReturn:(UITextField *)textField { - [textField resignFirstResponder]; + [textField resignFirstResponder]; return YES; } @@ -358,10 +358,10 @@ } - (BOOL)textFieldShouldEndEditing:(UITextField *)textField { - UIView *view = [textField superview]; + UIView *view = [textField superview]; // Find TableViewCell while(view != nil && ![view isKindOfClass:[UIEditableTableViewCell class]]) view = [view superview]; - + if(view != nil) { UIEditableTableViewCell *cell = (UIEditableTableViewCell*)view; NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; @@ -370,10 +370,10 @@ NSError* error = NULL; ABRecordSetValue(contact, property, [textField text], (CFErrorRef*)&error); if (error != NULL) { - [LinphoneLogger log:LinphoneLoggerError format:@"Error when saving property %i in contact %p: Fail(%@)", property, contact, [error localizedDescription]]; - } + LOGE(@"Error when saving property %i in contact %p: Fail(%@)", property, contact, [error localizedDescription]); + } } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Not valid UIEditableTableViewCell"]; + LOGW(@"Not valid UIEditableTableViewCell"); } if(contactDetailsDelegate != nil) { //add a mini delay to have the text updated BEFORE notifying the selector diff --git a/Classes/LinphoneUI/UIHistoryCell.m b/Classes/LinphoneUI/UIHistoryCell.m index 2f9b9d82d..fbda68674 100644 --- a/Classes/LinphoneUI/UIHistoryCell.m +++ b/Classes/LinphoneUI/UIHistoryCell.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "UIHistoryCell.h" #import "LinphoneManager.h" @@ -37,11 +37,11 @@ NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"UIHistoryCell" owner:self options:nil]; - + if ([arrayOfViews count] >= 1) { [self.contentView addSubview:[arrayOfViews objectAtIndex:0]]; } - + self->callLog = NULL; } return self; @@ -52,7 +52,7 @@ [deleteButton release]; [addressLabel release]; [imageView release]; - + [super dealloc]; } @@ -79,7 +79,7 @@ - (IBAction)onDelete:(id)event { if(callLog != NULL) { - UIView *view = [self superview]; + UIView *view = [self superview]; // Find TableViewCell while(view != nil && ![view isKindOfClass:[UITableView class]]) view = [view superview]; if(view != nil) { @@ -91,7 +91,7 @@ } -#pragma mark - +#pragma mark - - (NSString *)accessibilityValue { // TODO: localize? @@ -108,12 +108,12 @@ - (void)update { if(callLog == NULL) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update history cell: null callLog"]; + LOGW(@"Cannot update history cell: null callLog"); return; } - + // Set up the cell... - LinphoneAddress* addr; + LinphoneAddress* addr; UIImage *image; if (linphone_call_log_get_dir(callLog) == LinphoneCallIncoming) { if (linphone_call_log_get_status(callLog) != LinphoneCallMissed) { @@ -126,11 +126,11 @@ image = [UIImage imageNamed:@"call_status_outgoing.png"]; addr = linphone_call_log_get_to(callLog); } - + NSString* address = nil; if(addr != NULL) { BOOL useLinphoneAddress = true; - // contact name + // contact name char* lAddress = linphone_address_as_string_uri_only(addr); if(lAddress) { NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:lAddress]]; @@ -144,9 +144,9 @@ if(useLinphoneAddress) { const char* lDisplayName = linphone_address_get_display_name(addr); const char* lUserName = linphone_address_get_username(addr); - if (lDisplayName) + if (lDisplayName) address = [NSString stringWithUTF8String:lDisplayName]; - else if(lUserName) + else if(lUserName) address = [NSString stringWithUTF8String:lUserName]; } } @@ -169,10 +169,10 @@ } if(editing) { [deleteButton setAlpha:1.0f]; - [detailsButton setAlpha:0.0f]; + [detailsButton setAlpha:0.0f]; } else { [detailsButton setAlpha:1.0f]; - [deleteButton setAlpha:0.0f]; + [deleteButton setAlpha:0.0f]; } if(animated) { [UIView commitAnimations]; diff --git a/Classes/LinphoneUI/UILinphone.m b/Classes/LinphoneUI/UILinphone.m index edc2d5b51..c069f9f8a 100644 --- a/Classes/LinphoneUI/UILinphone.m +++ b/Classes/LinphoneUI/UILinphone.m @@ -28,12 +28,12 @@ - (UIColor *)lumColor:(float)mult { float hsbH, hsbS, hsbB; float rgbaR, rgbaG, rgbaB, rgbaA; - + // Get RGB CGColorRef cgColor = [self CGColor]; CGColorSpaceRef cgColorSpace = CGColorGetColorSpace(cgColor); if(CGColorSpaceGetModel(cgColorSpace) != kCGColorSpaceModelRGB) { - [LinphoneLogger log:LinphoneLoggerWarning format:@"Can't convert not RGB color"]; + LOGW(@"Can't convert not RGB color"); return self; } else { const CGFloat *colors = CGColorGetComponents(cgColor); @@ -42,26 +42,26 @@ rgbaB = colors[2]; rgbaA = CGColorGetAlpha(cgColor); } - + RGB2HSL(rgbaR, rgbaG, rgbaB, &hsbH, &hsbS, &hsbB); - + hsbB = MIN(MAX(hsbB * mult, 0.0), 1.0); - + HSL2RGB(hsbH, hsbS, hsbB, &rgbaR, &rgbaG, &rgbaB); - + return [UIColor colorWithRed:rgbaR green:rgbaG blue:rgbaB alpha:rgbaA]; } - (UIColor *)adjustHue:(float)hm saturation:(float)sm brightness:(float)bm alpha:(float)am { float hsbH, hsbS, hsbB; float rgbaR, rgbaG, rgbaB, rgbaA; - - + + // Get RGB CGColorRef cgColor = [self CGColor]; CGColorSpaceRef cgColorSpace = CGColorGetColorSpace(cgColor); if(CGColorSpaceGetModel(cgColorSpace) != kCGColorSpaceModelRGB) { - [LinphoneLogger log:LinphoneLoggerWarning format:@"Can't convert not RGB color"]; + LOGW(@"Can't convert not RGB color"); return self; } else { const CGFloat *colors = CGColorGetComponents(cgColor); @@ -70,16 +70,16 @@ rgbaB = colors[2]; rgbaA = CGColorGetAlpha(cgColor); } - + RGB2HSL(rgbaR, rgbaG, rgbaB, &hsbH, &hsbS, &hsbB); - + hsbH = MIN(MAX(hsbH + hm, 0.0), 1.0); hsbS = MIN(MAX(hsbS + sm, 0.0), 1.0); hsbB = MIN(MAX(hsbB + bm, 0.0), 1.0); rgbaA = MIN(MAX(rgbaA + am, 0.0), 1.0); - + HSL2RGB(hsbH, hsbS, hsbB, &rgbaR, &rgbaG, &rgbaB); - + return [UIColor colorWithRed:rgbaR green:rgbaG blue:rgbaB alpha:rgbaA]; } @@ -114,12 +114,12 @@ kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Little); CGColorSpaceRelease(colorSpace); if (!context) return nil; - + CGRect rect = (CGRect){CGPointZero,{CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)}}; CGContextDrawImage(context, rect, imageRef); CGImageRef decompressedImageRef = CGBitmapContextCreateImage(context); CGContextRelease(context); - + UIImage *decompressedImage = [[UIImage alloc] initWithCGImage:decompressedImageRef scale:image.scale orientation:image.imageOrientation]; CGImageRelease(decompressedImageRef); return [decompressedImage autorelease]; diff --git a/Classes/LinphoneUI/UIPauseButton.m b/Classes/LinphoneUI/UIPauseButton.m index adf20f954..88bb64875 100644 --- a/Classes/LinphoneUI/UIPauseButton.m +++ b/Classes/LinphoneUI/UIPauseButton.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "UIPauseButton.h" #import "LinphoneManager.h" @@ -46,7 +46,7 @@ [self initUIPauseButton]; } return self; -} +} - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; @@ -68,7 +68,7 @@ + (int)notInConferenceCallCount: (LinphoneCore*) lc { int count = 0; const MSList* calls = linphone_core_get_calls(lc); - + while (calls != 0) { if (![UIPauseButton isInConference: (LinphoneCall*)calls->data]) { count++; @@ -88,7 +88,7 @@ } -#pragma mark - +#pragma mark - - (void)setType:(UIPauseButtonType) atype call:(LinphoneCall*)acall { type = atype; @@ -105,14 +105,14 @@ if (call != nil) { linphone_core_pause_call([LinphoneManager getLc], call); } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle pause buttton, because no current call"]; + LOGW(@"Cannot toggle pause buttton, because no current call"); } break; } case UIPauseButtonType_Conference: { linphone_core_leave_conference([LinphoneManager getLc]); - + // Fake event [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneCallUpdate object:self]; break; @@ -123,7 +123,7 @@ if (currentCall != nil) { linphone_core_pause_call([LinphoneManager getLc], currentCall); } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle pause buttton, because no current call"]; + LOGW(@"Cannot toggle pause buttton, because no current call"); } break; } @@ -137,7 +137,7 @@ if (call != nil) { linphone_core_resume_call([LinphoneManager getLc], call); } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle pause buttton, because no current call"]; + LOGW(@"Cannot toggle pause buttton, because no current call"); } break; } @@ -154,7 +154,7 @@ if (currentCall != nil) { linphone_core_resume_call([LinphoneManager getLc], currentCall); } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle pause buttton, because no current call"]; + LOGW(@"Cannot toggle pause buttton, because no current call"); } break; } diff --git a/Classes/LinphoneUI/UISpeakerButton.m b/Classes/LinphoneUI/UISpeakerButton.m index 2fd073c60..9e21f3997 100644 --- a/Classes/LinphoneUI/UISpeakerButton.m +++ b/Classes/LinphoneUI/UISpeakerButton.m @@ -44,7 +44,7 @@ static void audioRouteChangeListenerCallback ( AudioSessionInitialize(NULL, NULL, NULL, NULL); OSStatus lStatus = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, audioRouteChangeListenerCallback, self); if (lStatus) { - [LinphoneLogger logc:LinphoneLoggerError format:"cannot register route change handler [%ld]",lStatus]; + LOGE(@"cannot register route change handler [%ld]",lStatus); } } @@ -75,7 +75,7 @@ static void audioRouteChangeListenerCallback ( - (void)dealloc { OSStatus lStatus = AudioSessionRemovePropertyListenerWithUserData(kAudioSessionProperty_AudioRouteChange, audioRouteChangeListenerCallback, self); if (lStatus) { - [LinphoneLogger logc:LinphoneLoggerError format:"cannot un register route change handler [%ld]", lStatus]; + LOGE(@"cannot un register route change handler [%ld]", lStatus); } [super dealloc]; } diff --git a/Classes/LinphoneUI/UIStateBar.m b/Classes/LinphoneUI/UIStateBar.m index 80c36f97a..02e553283 100644 --- a/Classes/LinphoneUI/UIStateBar.m +++ b/Classes/LinphoneUI/UIStateBar.m @@ -167,13 +167,13 @@ int messagesUnreadCount; } const char* body = linphone_content_get_buffer(content); if ((body = strstr(body, "voice-message: ")) == NULL) { - [LinphoneLogger log:LinphoneLoggerWarning format:@"Received new NOTIFY from voice mail but could not find 'voice-message' in BODY. Ignoring it."]; + LOGW(@"Received new NOTIFY from voice mail but could not find 'voice-message' in BODY. Ignoring it."); return; } sscanf(body, "voice-message: %d", &messagesUnreadCount); - [LinphoneLogger log:LinphoneLoggerLog format:@"Received new NOTIFY from voice mail: there is/are now %d message(s) unread", messagesUnreadCount]; + LOGI(@"Received new NOTIFY from voice mail: there is/are now %d message(s) unread", messagesUnreadCount); // save in lpconfig for future lp_config_set_int(linphone_core_get_config([LinphoneManager getLc]), "app", "voice_mail_messages_count", messagesUnreadCount); diff --git a/Classes/LinphoneUI/UIVideoButton.m b/Classes/LinphoneUI/UIVideoButton.m index 1edd7f0b3..0a7bd358c 100644 --- a/Classes/LinphoneUI/UIVideoButton.m +++ b/Classes/LinphoneUI/UIVideoButton.m @@ -72,7 +72,7 @@ linphone_core_update_call(lc, call, call_params); linphone_call_params_destroy(call_params); } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle video button, because no current call"]; + LOGW(@"Cannot toggle video button, because no current call"); } } @@ -92,7 +92,7 @@ linphone_core_update_call(lc, call, call_params); linphone_call_params_destroy(call_params); } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle video button, because no current call"]; + LOGW(@"Cannot toggle video button, because no current call"); } } diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index e1ad68ec9..b8004a291 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import #import @@ -145,7 +145,7 @@ static RootViewManager* rootViewManagerInstance = nil; - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; - + [mainViewController release]; [inhibitedEvents release]; @@ -169,16 +169,16 @@ static RootViewManager* rootViewManagerInstance = nil; [super viewWillAppear:animated]; // Set observers - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(callUpdate:) + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(callUpdate:) name:kLinphoneCallUpdate object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(registrationUpdate:) + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(registrationUpdate:) name:kLinphoneRegistrationUpdate object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(textReceived:) + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(textReceived:) name:kLinphoneTextReceived object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self @@ -187,7 +187,7 @@ static RootViewManager* rootViewManagerInstance = nil; object:nil]; [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(batteryLevelChanged:) + selector:@selector(batteryLevelChanged:) name:UIDeviceBatteryLevelDidChangeNotification object:nil]; @@ -197,10 +197,10 @@ static RootViewManager* rootViewManagerInstance = nil; [super viewWillDisappear:animated]; // Remove observers - [[NSNotificationCenter defaultCenter] removeObserver:self + [[NSNotificationCenter defaultCenter] removeObserver:self name:kLinphoneCallUpdate object:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self + [[NSNotificationCenter defaultCenter] removeObserver:self name:kLinphoneRegistrationUpdate object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self @@ -210,10 +210,10 @@ static RootViewManager* rootViewManagerInstance = nil; name:kLinphoneConfiguringStateUpdate object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self - name:UIDeviceBatteryLevelDidChangeNotification + name:UIDeviceBatteryLevelDidChangeNotification object:nil]; [[UIDevice currentDevice] setBatteryMonitoringEnabled:NO]; - + } -(void)viewDidAppear:(BOOL)animated { @@ -270,7 +270,7 @@ static RootViewManager* rootViewManagerInstance = nil; #pragma mark - Event Functions -- (void)textReceived:(NSNotification*)notif { +- (void)textReceived:(NSNotification*)notif { LinphoneAddress* from = [[notif.userInfo objectForKey:@"from_address"] pointerValue]; NSString* callID = [notif.userInfo objectForKey:@"call-id"]; if(from != nil) { @@ -316,22 +316,22 @@ static RootViewManager* rootViewManagerInstance = nil; LinphoneCall *call = [[notif.userInfo objectForKey: @"call"] pointerValue]; LinphoneCallState state = [[notif.userInfo objectForKey: @"state"] intValue]; NSString *message = [notif.userInfo objectForKey: @"message"]; - + bool canHideInCallView = (linphone_core_get_calls([LinphoneManager getLc]) == NULL); - + // Don't handle call state during incoming call view if([[self currentView] equal:[IncomingCallViewController compositeViewDescription]] && state != LinphoneCallError && state != LinphoneCallEnd) { return; } - - switch (state) { - case LinphoneCallIncomingReceived: + + switch (state) { + case LinphoneCallIncomingReceived: case LinphoneCallIncomingEarlyMedia: { [self displayIncomingCall:call]; break; } - case LinphoneCallOutgoingInit: + case LinphoneCallOutgoingInit: case LinphoneCallPausedByRemote: case LinphoneCallConnected: case LinphoneCallStreamsRunning: @@ -343,7 +343,7 @@ static RootViewManager* rootViewManagerInstance = nil; { const LinphoneCallParams* current = linphone_call_get_current_params(call); const LinphoneCallParams* remote = linphone_call_get_remote_params(call); - + if (linphone_call_params_video_enabled(current) && !linphone_call_params_video_enabled(remote)) { [self changeCurrentView:[InCallViewController compositeViewDescription]]; } @@ -353,7 +353,7 @@ static RootViewManager* rootViewManagerInstance = nil; { [self displayCallError:call message: message]; } - case LinphoneCallEnd: + case LinphoneCallEnd: { if (canHideInCallView) { // Go to dialer view @@ -374,7 +374,7 @@ static RootViewManager* rootViewManagerInstance = nil; } -#pragma mark - +#pragma mark - - (void)orientationUpdate:(UIInterfaceOrientation)orientation { int oldLinphoneOrientation = linphone_core_get_device_rotation([LinphoneManager getLc]); @@ -451,7 +451,7 @@ static RootViewManager* rootViewManagerInstance = nil; [trans setDuration:0.35]; [trans setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [trans setSubtype:transition]; - + return trans; } @@ -463,13 +463,13 @@ static RootViewManager* rootViewManagerInstance = nil; [trans setDuration:0.35]; [trans setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [trans setSubtype:transition]; - + return trans; } + (CATransition*)getTransition:(UICompositeViewDescription *)old new:(UICompositeViewDescription *)new { bool left = false; - + if([old equal:[ChatViewController compositeViewDescription]]) { if([new equal:[ContactsViewController compositeViewDescription]] || [new equal:[DialerViewController compositeViewDescription]] || @@ -492,7 +492,7 @@ static RootViewManager* rootViewManagerInstance = nil; if([new equal:[HistoryViewController compositeViewDescription]]) { left = true; } - } + } if(left) { return [PhoneMainView getBackwardTransition]; @@ -558,7 +558,7 @@ static RootViewManager* rootViewManagerInstance = nil; } - (UIViewController*)_changeCurrentView:(UICompositeViewDescription*)view transition:(CATransition*)transition force:(BOOL)force { - [LinphoneLogger logc:LinphoneLoggerLog format:"PhoneMainView: Change current view to %@", [view name]]; + LOGI(@"PhoneMainView: Change current view to %@", [view name]); PhoneMainView* vc = [[RootViewManager instance] setViewControllerForDescription:view]; @@ -576,10 +576,10 @@ static RootViewManager* rootViewManagerInstance = nil; } //[[RootViewManager instance] setViewControllerForDescription:view]; - + NSDictionary* mdict = [NSMutableDictionary dictionaryWithObject:vc->currentView forKey:@"view"]; [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneMainViewChange object:self userInfo:mdict]; - + return [vc->mainViewController getCurrentViewController]; } @@ -601,13 +601,13 @@ static RootViewManager* rootViewManagerInstance = nil; } - (UIViewController*)popCurrentView { - [LinphoneLogger logc:LinphoneLoggerLog format:"PhoneMainView: Pop view"]; + LOGI(@"PhoneMainView: Pop view"); NSMutableArray* viewStack = [RootViewManager instance].viewDescriptionStack; if([viewStack count] > 1) { [viewStack removeLastObject]; [self _changeCurrentView:[viewStack lastObject] transition:[PhoneMainView getBackwardTransition] force:TRUE]; return [mainViewController getCurrentViewController]; - } + } return nil; } @@ -616,16 +616,16 @@ static RootViewManager* rootViewManagerInstance = nil; NSString* lUserName = lUserNameChars?[[[NSString alloc] initWithUTF8String:lUserNameChars] autorelease]:NSLocalizedString(@"Unknown",nil); NSString* lMessage; NSString* lTitle; - + //get default proxy - LinphoneProxyConfig* proxyCfg; + LinphoneProxyConfig* proxyCfg; linphone_core_get_default_proxy([LinphoneManager getLc],&proxyCfg); if (proxyCfg == nil) { lMessage = NSLocalizedString(@"Please make sure your device is connected to the internet and double check your SIP account configuration in the settings.", nil); } else { lMessage = [NSString stringWithFormat : NSLocalizedString(@"Cannot call %@", nil), lUserName]; } - + if (linphone_call_get_reason(call) == LinphoneReasonNotFound) { lMessage = [NSString stringWithFormat : NSLocalizedString(@"'%@' not registered", nil), lUserName]; } else { @@ -635,9 +635,9 @@ static RootViewManager* rootViewManagerInstance = nil; } lTitle = NSLocalizedString(@"Call failed",nil); UIAlertView* error = [[UIAlertView alloc] initWithTitle:lTitle - message:lMessage - delegate:nil - cancelButtonTitle:NSLocalizedString(@"Dismiss",nil) + message:lMessage + delegate:nil + cancelButtonTitle:NSLocalizedString(@"Dismiss",nil) otherButtonTitles:nil]; [error show]; [error release]; @@ -703,15 +703,15 @@ static RootViewManager* rootViewManagerInstance = nil; - (void)batteryLevelChanged:(NSNotification*)notif { float level = [UIDevice currentDevice].batteryLevel; UIDeviceBatteryState state = [UIDevice currentDevice].batteryState; - [LinphoneLogger log:LinphoneLoggerDebug format:@"Battery state:%d level:%.2f", state, level]; - + LOGD(@"Battery state:%d level:%.2f", state, level); + LinphoneCall* call = linphone_core_get_current_call([LinphoneManager getLc]); if (call && linphone_call_params_video_enabled(linphone_call_get_current_params(call))) { LinphoneCallAppData* callData = (LinphoneCallAppData*) linphone_call_get_user_pointer(call); if(callData != nil) { if (state == UIDeviceBatteryStateUnplugged) { if (level <= 0.2f && !callData->batteryWarningShown) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Battery warning"]; + LOGI(@"Battery warning"); DTActionSheet *sheet = [[[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Battery is running low. Stop video ?",nil)] autorelease]; [sheet addCancelButtonWithTitle:NSLocalizedString(@"Continue video", nil) block:nil]; [sheet addDestructiveButtonWithTitle:NSLocalizedString(@"Stop video", nil) block:^() { @@ -745,4 +745,4 @@ static RootViewManager* rootViewManagerInstance = nil; linphone_core_terminate_call([LinphoneManager getLc], call); } -@end \ No newline at end of file +@end diff --git a/Classes/SettingsViewController.m b/Classes/SettingsViewController.m index d200f59e3..5e058c26a 100644 --- a/Classes/SettingsViewController.m +++ b/Classes/SettingsViewController.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "SettingsViewController.h" #import "LinphoneManager.h" @@ -67,7 +67,7 @@ - (void)dealloc { [_key release], _key = nil; - + [super dealloc]; } @@ -113,7 +113,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell * cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; - + // Background View UACellBackgroundView *selectedBackgroundView = [[[UACellBackgroundView alloc] initWithFrame:CGRectZero] autorelease]; cell.selectedBackgroundView = selectedBackgroundView; @@ -155,7 +155,7 @@ - (void)toggledValue:(id)sender { IASKSwitchEx *toggle = [[(IASKSwitchEx*)sender retain] autorelease]; IASKSpecifier *spec = [_settingsReader specifierForKey:[toggle key]]; - + if ([toggle isOn]) { if ([spec trueValue] != nil) { [self.settingsStore setObject:[spec trueValue] forKey:[toggle key]]; @@ -183,16 +183,16 @@ - (void)initIASKAppSettingsViewControllerEx { [self.view setBackgroundColor:[UIColor clearColor]]; - + // Force kIASKSpecifierValuesViewControllerIndex static int kIASKSpecifierValuesViewControllerIndex = 0; _viewList = [[NSMutableArray alloc] init]; [_viewList addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"IASKSpecifierValuesView", @"ViewName",nil]]; [_viewList addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"IASKAppSettingsView", @"ViewName",nil]]; - + NSMutableDictionary *newItemDict = [NSMutableDictionary dictionaryWithCapacity:3]; [newItemDict addEntriesFromDictionary: [_viewList objectAtIndex:kIASKSpecifierValuesViewControllerIndex]]; // copy the title and explain strings - + IASKSpecifierValuesViewController *targetViewController = [[IASKSpecifierValuesViewControllerEx alloc] init]; // add the new view controller to the dictionary and then to the 'viewList' array [newItemDict setObject:targetViewController forKey:@"viewController"]; @@ -212,7 +212,7 @@ } [specifiers replaceObjectAtIndex:j withObject:sp]; } - + [dataSource replaceObjectAtIndex:i withObject:specifiers]; } [r setDataSource:dataSource]; @@ -222,7 +222,7 @@ - (void)viewDidLoad { [super viewDidLoad]; - + [self.tableView setBackgroundColor:[UIColor clearColor]]; // Can't do it in Xib: issue with ios4 [self.tableView setBackgroundView:nil]; // Can't do it in Xib: issue with ios4 } @@ -237,8 +237,8 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - - + + UIEdgeInsets inset = {0, 0, 10, 0}; UIScrollView *scrollView = self.tableView; [scrollView setContentInset:inset]; @@ -247,7 +247,7 @@ - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - + UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"About", nil) style:UIBarButtonItemStyleBordered target:self action:@selector(onAboutClick:)]; self.navigationItem.rightBarButtonItem = buttonItem; [buttonItem release]; @@ -255,7 +255,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell * cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; - + if([cell isKindOfClass:[IASKPSTextFieldSpecifierViewCell class]]) { UITextField *field = ((IASKPSTextFieldSpecifierViewCell*)cell).textField; [field setTextColor:LINPHONE_MAIN_COLOR]; @@ -266,7 +266,7 @@ } else { cell.detailTextLabel.textColor = LINPHONE_MAIN_COLOR; } - + // Background View UACellBackgroundView *selectedBackgroundView = [[[UACellBackgroundView alloc] initWithFrame:CGRectZero] autorelease]; cell.selectedBackgroundView = selectedBackgroundView; @@ -284,7 +284,7 @@ #pragma mark - UINavigationBarEx Class @interface UINavigationBarEx: UINavigationBar { - + } @end @@ -413,12 +413,12 @@ static UICompositeViewDescription *compositeDescription = nil; + (UICompositeViewDescription *)compositeViewDescription { if(compositeDescription == nil) { - compositeDescription = [[UICompositeViewDescription alloc] init:@"Settings" - content:@"SettingsViewController" - stateBar:nil - stateBarEnabled:false - tabBar: @"UIMainBar" - tabBarEnabled:true + compositeDescription = [[UICompositeViewDescription alloc] init:@"Settings" + content:@"SettingsViewController" + stateBar:nil + stateBarEnabled:false + tabBar: @"UIMainBar" + tabBarEnabled:true fullscreen:false landscapeMode:[LinphoneManager runningOnIpad] portraitMode:true]; @@ -431,16 +431,16 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewDidLoad { [super viewDidLoad]; - + settingsStore = [[LinphoneCoreSettingsStore alloc] init]; - + settingsController.showDoneButton = FALSE; settingsController.delegate = self; settingsController.showCreditsFooter = FALSE; settingsController.settingsStore = settingsStore; - + [navigationController.view setBackgroundColor:[UIColor clearColor]]; - + navigationController.view.frame = self.view.frame; [navigationController pushViewController:settingsController animated:FALSE]; [self.view addSubview: navigationController.view]; @@ -450,24 +450,24 @@ static UICompositeViewDescription *compositeDescription = nil; [super viewWillDisappear:animated]; [settingsController dismiss:self]; // Set observer - [[NSNotificationCenter defaultCenter] removeObserver:self - name:kIASKAppSettingChanged + [[NSNotificationCenter defaultCenter] removeObserver:self + name:kIASKAppSettingChanged object:nil]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - + [settingsStore transformLinphoneCoreToKeys]; // Sync settings with linphone core settings settingsController.hiddenKeys = [self findHiddenKeys]; - [settingsController.tableView reloadData]; - + [settingsController.tableView reloadData]; + // Set observer - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(appSettingChanged:) + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(appSettingChanged:) name:kIASKAppSettingChanged object:nil]; - + } @@ -594,7 +594,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (NSSet*)findHiddenKeys { LinphoneManager* lm = [LinphoneManager instance]; NSMutableSet *hiddenKeys = [NSMutableSet set]; - + #ifndef DEBUG [hiddenKeys addObject:@"release_button"]; [hiddenKeys addObject:@"clear_cache_button"]; @@ -608,25 +608,25 @@ static UICompositeViewDescription *compositeDescription = nil; [hiddenKeys addObject:@"playback_gain_preference"]; [hiddenKeys addObject:@"microphone_gain_preference"]; - + [hiddenKeys addObject:@"network_limit_group"]; [hiddenKeys addObject:@"upload_bandwidth_preference"]; [hiddenKeys addObject:@"download_bandwidth_preference"]; - + [hiddenKeys addObject:@"incoming_call_timeout_preference"]; [hiddenKeys addObject:@"in_call_timeout_preference"]; - + [hiddenKeys addObject:@"wifi_only_preference"]; - + [hiddenKeys addObject:@"quit_button"]; // Hide for the moment [hiddenKeys addObject:@"about_button"]; // Hide for the moment - + if (!linphone_core_video_supported([LinphoneManager getLc])) [hiddenKeys addObject:@"video_menu"]; - + if (![LinphoneManager isNotIphone3G]) [hiddenKeys addObject:@"silk_24k_preference"]; - + UIDevice* device = [UIDevice currentDevice]; if (![device respondsToSelector:@selector(isMultitaskingSupported)] || ![device isMultitaskingSupported]) { [hiddenKeys addObject:@"backgroundmode_preference"]; @@ -636,18 +636,18 @@ static UICompositeViewDescription *compositeDescription = nil; [hiddenKeys addObject:@"start_at_boot_preference"]; } } - + [hiddenKeys addObject:@"enable_first_login_view_preference"]; - + #ifndef VIDEO_ENABLED [hiddenKeys addObject:@"enable_video_preference"]; #endif //VIDEO_ENABLED - + if (!linphone_core_video_enabled([LinphoneManager getLc])) { [hiddenKeys addObject:@"video_menu"]; } - - + + [hiddenKeys addObjectsFromArray:[[LinphoneManager unsupportedCodecs] allObjects]]; BOOL random_port = [lm lpConfigBoolForKey:@"random_port_preference"]; @@ -662,14 +662,14 @@ static UICompositeViewDescription *compositeDescription = nil; if(![lm lpConfigBoolForKey:@"debugenable_preference"]) { [hiddenKeys addObject:@"console_button"]; } - + if(![LinphoneManager runningOnIpad]) { [hiddenKeys addObject:@"preview_preference"]; } if([lm lpConfigBoolForKey:@"hide_run_assistant_preference"]) { [hiddenKeys addObject:@"wizard_button"]; } - + if (!linphone_core_tunnel_available()){ [hiddenKeys addObject:@"tunnel_menu"]; } @@ -750,7 +750,7 @@ static UICompositeViewDescription *compositeDescription = nil; } else if ([key isEqual:@"send_logs_button"]) { char * filepath = linphone_core_compress_log_collection(lc); if (filepath == NULL) { - [LinphoneLogger log:LinphoneLoggerError format:@"Cannot sent logs: file is NULL"]; + LOGE(@"Cannot sent logs: file is NULL"); return; } @@ -767,7 +767,7 @@ static UICompositeViewDescription *compositeDescription = nil; } else if ([filename hasSuffix:@".gz"]) { mimeType = @"application/gzip"; } else { - [LinphoneLogger log:LinphoneLoggerError format:@"Unknown extension type: %@, cancelling email", filename]; + LOGE(@"Unknown extension type: %@, cancelling email", filename); return; } [self emailAttachment:[NSData dataWithContentsOfFile:[NSString stringWithUTF8String:filepath]] mimeType:mimeType name:filename]; @@ -788,7 +788,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)emailAttachment: (NSData*)attachment mimeType:(NSString*)type name:(NSString*)attachmentName { if (attachmentName == nil || type == nil || attachmentName == nil) { - [LinphoneLogger log:LinphoneLoggerError format:@"Trying to email attachment but mandatory field is missing"]; + LOGE(@"Trying to email attachment but mandatory field is missing"); return; } @@ -827,9 +827,9 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { if (error != nil) { - [LinphoneLogger log:LinphoneLoggerWarning format:@"Error while sending mail: %@", error]; + LOGW(@"Error while sending mail: %@", error); } else { - [LinphoneLogger log:LinphoneLoggerLog format:@"Mail completed with status: %d", result]; + LOGI(@"Mail completed with status: %d", result); } [self dismissViewControllerAnimated:true completion:nil]; } diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index 612b0b8c4..042839cd1 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -77,7 +77,7 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf } if (retImage != nil && retImage.size.width != retImage.size.height) { - [LinphoneLogger log:LinphoneLoggerLog format:@"Image is not square : cropping it."]; + LOGI(@"Image is not square : cropping it."); return [self squareImageCrop:retImage]; } } @@ -107,7 +107,7 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf } + (NSString*)normalizeSipURI:(NSString*)address { - // replace all whitespaces (non-breakable, utf8 nbsp etc.) by the "classical" whitespace + // replace all whitespaces (non-breakable, utf8 nbsp etc.) by the "classical" whitespace address = [[address componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] componentsJoinedByString:@" "]; NSString *normalizedSipAddress = nil; LinphoneAddress* linphoneAddress = linphone_core_interpret_url([LinphoneManager getLc], [address UTF8String]); @@ -185,7 +185,7 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf [self loadData]; }); } else { - [LinphoneLogger log:LinphoneLoggerError format:@"Create AddressBook: Fail(%@)", [error localizedDescription]]; + LOGE(@"Create AddressBook: Fail(%@)", [error localizedDescription]); } } diff --git a/Classes/Utils/Utils.h b/Classes/Utils/Utils.h index 0edac128a..8e210c001 100644 --- a/Classes/Utils/Utils.h +++ b/Classes/Utils/Utils.h @@ -38,8 +38,7 @@ typedef enum _LinphoneLoggerSeverity { @interface LinphoneLogger : NSObject { } -+ (void)log:(LinphoneLoggerSeverity) severity format:(NSString *)format,...; -+ (void)logc:(LinphoneLoggerSeverity) severity format:(const char *)format,...; ++ (void)log:(LinphoneLoggerSeverity)severity file:(const char*)file line:(int)line format:(NSString *)format,...; @end @@ -62,7 +61,7 @@ typedef enum _LinphoneLoggerSeverity { @end -#define LOGV(level, ...) [LinphoneLogger log:level format:__VA_ARGS__] +#define LOGV(level, ...) [LinphoneLogger log:level file:__FILE__ line:__LINE__ format:__VA_ARGS__] #define LOGI(...) LOGV(LinphoneLoggerLog, __VA_ARGS__) #define LOGD(...) LOGV(LinphoneLoggerDebug, __VA_ARGS__) #define LOGW(...) LOGV(LinphoneLoggerWarning, __VA_ARGS__) diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index 8cdde9661..b15ee923f 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -24,36 +24,32 @@ @implementation LinphoneLogger -+ (void)logv:(LinphoneLoggerSeverity)severity format:(NSString*)format args:(va_list)args{ ++ (void)logv:(LinphoneLoggerSeverity)severity file:(const char*)file line:(int)line format:(NSString*)format args:(va_list)args{ NSString *str = [[NSString alloc] initWithFormat:format arguments:args]; - [self logc:severity format:[str UTF8String]]; + OrtpLogLevel ortp_severity; + int filesize = 20; + if (severity <= LinphoneLoggerDebug) { + ortp_severity = ORTP_DEBUG; + } else if(severity <= LinphoneLoggerLog) { + ortp_severity = ORTP_MESSAGE; + } else if(severity <= LinphoneLoggerWarning) { + ortp_severity = ORTP_WARNING; + } else if(severity <= LinphoneLoggerError) { + ortp_severity = ORTP_ERROR; + } else { + ortp_severity = ORTP_FATAL; + } + ortp_log(ortp_severity, "%*s:%3d - %s", filesize, file+MAX((int)strlen(file)-filesize,0), line, [str UTF8String]); [str release]; } -+ (void)log:(LinphoneLoggerSeverity) severity format:(NSString *)format,... { ++ (void)log:(LinphoneLoggerSeverity) severity file:(const char*)file line:(int)line format:(NSString *)format,... { va_list args; va_start (args, format); - [LinphoneLogger logv:severity format:format args:args]; + [LinphoneLogger logv:severity file:file line:line format:format args:args]; va_end (args); } -+ (void)logc:(LinphoneLoggerSeverity) severity format:(const char *)format,... { - va_list args; - va_start (args, format); - if(severity <= LinphoneLoggerDebug) { - ortp_logv(ORTP_DEBUG, format, args); - } else if(severity <= LinphoneLoggerLog) { - ortp_logv(ORTP_MESSAGE, format, args); - } else if(severity <= LinphoneLoggerWarning) { - ortp_logv(ORTP_WARNING, format, args); - } else if(severity <= LinphoneLoggerError) { - ortp_logv(ORTP_ERROR, format, args); - } else if(severity <= LinphoneLoggerFatal) { - ortp_logv(ORTP_FATAL, format, args); - } - va_end (args); -} - @end @implementation LinphoneUtils diff --git a/Classes/WizardViewController.m b/Classes/WizardViewController.m index 69110d042..3e355576c 100644 --- a/Classes/WizardViewController.m +++ b/Classes/WizardViewController.m @@ -4,18 +4,18 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ + */ #import "WizardViewController.h" #import "LinphoneManager.h" @@ -83,18 +83,18 @@ typedef enum _ViewElement { - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; - + [contentView release]; - + [welcomeView release]; [choiceView release]; [createAccountView release]; [connectAccountView release]; [externalAccountView release]; [validateAccountView release]; - + [waitView release]; - + [backButton release]; [startButton release]; [createAccountButton release]; @@ -102,11 +102,11 @@ typedef enum _ViewElement { [externalAccountButton release]; [choiceViewLogoImageView release]; - + [historyViews release]; - + [viewTapGestureRecognizer release]; - + [remoteProvisioningButton release]; [provisionedAccountView release]; [provisionedUsername release]; @@ -123,12 +123,12 @@ static UICompositeViewDescription *compositeDescription = nil; + (UICompositeViewDescription *)compositeViewDescription { if(compositeDescription == nil) { - compositeDescription = [[UICompositeViewDescription alloc] init:@"Wizard" - content:@"WizardViewController" - stateBar:nil - stateBarEnabled:false - tabBar:nil - tabBarEnabled:false + compositeDescription = [[UICompositeViewDescription alloc] init:@"Wizard" + content:@"WizardViewController" + stateBar:nil + stateBarEnabled:false + tabBar:nil + tabBarEnabled:false fullscreen:false landscapeMode:[LinphoneManager runningOnIpad] portraitMode:true]; @@ -142,7 +142,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(registrationUpdateEvent:) name:kLinphoneRegistrationUpdate @@ -182,11 +182,11 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewDidLoad { [super viewDidLoad]; - + [viewTapGestureRecognizer setCancelsTouchesInView:FALSE]; [viewTapGestureRecognizer setDelegate:self]; [contentView addGestureRecognizer:viewTapGestureRecognizer]; - + if([LinphoneManager runningOnIpad]) { [LinphoneUtils adjustFontSize:welcomeView mult:2.22f]; [LinphoneUtils adjustFontSize:choiceView mult:2.22f]; @@ -226,7 +226,7 @@ static UICompositeViewDescription *compositeDescription = nil; const LinphoneAuthInfo *auth = linphone_core_find_auth_info(lc, NULL, linphone_address_get_username(addr), linphone_proxy_config_get_domain(current_conf)); linphone_address_destroy(addr); if( auth ){ - [LinphoneLogger log:LinphoneLoggerLog format:@"A proxy config was set up with the remote provisioning, skip wizard"]; + LOGI(@"A proxy config was set up with the remote provisioning, skip wizard"); [self onCancelClick:nil]; } } @@ -271,14 +271,14 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)reset { [self clearProxyConfig]; [[LinphoneManager instance] lpConfigSetBool:FALSE forKey:@"pushnotification_preference"]; - + LinphoneCore *lc = [LinphoneManager getLc]; LCSipTransports transportValue={5060,5060,-1,-1}; if (linphone_core_set_sip_transports(lc, &transportValue)) { - [LinphoneLogger logc:LinphoneLoggerError format:"cannot set transport"]; + LOGE(@"cannot set transport"); } - + [[LinphoneManager instance] lpConfigSetString:@"" forKey:@"sharing_server_preference"]; [[LinphoneManager instance] lpConfigSetBool:FALSE forKey:@"ice_preference"]; [[LinphoneManager instance] lpConfigSetString:@"" forKey:@"stun_preference"]; @@ -336,7 +336,7 @@ static UICompositeViewDescription *compositeDescription = nil; [startButton setHidden:true]; [backButton setHidden:false]; } - + if (view == validateAccountView) { [backButton setEnabled:FALSE]; } else if (view == choiceView) { @@ -384,7 +384,7 @@ static UICompositeViewDescription *compositeDescription = nil; view = connectAccountView; } } - + // Animation if(animation && [[LinphoneManager instance] lpConfigBoolForKey:@"animations_preference"] == true) { CATransition* trans = [CATransition animation]; @@ -398,14 +398,14 @@ static UICompositeViewDescription *compositeDescription = nil; } [contentView.layer addAnimation:trans forKey:@"Transition"]; } - + // Stack current view if(currentView != nil) { if(!back) [historyViews addObject:currentView]; [currentView removeFromSuperview]; } - + // Set current view currentView = view; [contentView insertSubview:view atIndex:0]; @@ -531,44 +531,44 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark - Linphone XMLRPC - (void)checkUserExist:(NSString*)username { - [LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC check_account %@", username]; - + LOGI(@"XMLRPC check_account %@", username); + NSURL *URL = [NSURL URLWithString:[[LinphoneManager instance] lpConfigStringForKey:@"service_url" forSection:@"wizard"]]; XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL]; [request setMethod: @"check_account" withParameters:[NSArray arrayWithObjects:username, nil]]; - + XMLRPCConnectionManager *manager = [XMLRPCConnectionManager sharedManager]; [manager spawnConnectionWithXMLRPCRequest: request delegate: self]; - + [request release]; [waitView setHidden:false]; } - (void)createAccount:(NSString*)identity password:(NSString*)password email:(NSString*)email { NSString *useragent = [LinphoneManager getUserAgent]; - [LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC create_account_with_useragent %@ %@ %@ %@", identity, password, email, useragent]; - + LOGI(@"XMLRPC create_account_with_useragent %@ %@ %@ %@", identity, password, email, useragent); + NSURL *URL = [NSURL URLWithString: [[LinphoneManager instance] lpConfigStringForKey:@"service_url" forSection:@"wizard"]]; XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL]; [request setMethod: @"create_account_with_useragent" withParameters:[NSArray arrayWithObjects:identity, password, email, useragent, nil]]; - + XMLRPCConnectionManager *manager = [XMLRPCConnectionManager sharedManager]; [manager spawnConnectionWithXMLRPCRequest: request delegate: self]; - + [request release]; [waitView setHidden:false]; } - (void)checkAccountValidation:(NSString*)identity { - [LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC check_account_validated %@", identity]; - + LOGI(@"XMLRPC check_account_validated %@", identity); + NSURL *URL = [NSURL URLWithString: [[LinphoneManager instance] lpConfigStringForKey:@"service_url" forSection:@"wizard"]]; XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL]; [request setMethod: @"check_account_validated" withParameters:[NSArray arrayWithObjects:identity, nil]]; - + XMLRPCConnectionManager *manager = [XMLRPCConnectionManager sharedManager]; [manager spawnConnectionWithXMLRPCRequest: request delegate: self]; - + [request release]; [waitView setHidden:false]; } @@ -792,19 +792,19 @@ static UICompositeViewDescription *compositeDescription = nil; NSInteger username_length = [[LinphoneManager instance] lpConfigIntForKey:@"username_length" forSection:@"wizard"]; NSInteger password_length = [[LinphoneManager instance] lpConfigIntForKey:@"password_length" forSection:@"wizard"]; - + if ([username length] < username_length) { [errors appendString:[NSString stringWithFormat:NSLocalizedString(@"The username is too short (minimum %d characters).\n", nil), username_length]]; } - + if ([password length] < password_length) { [errors appendString:[NSString stringWithFormat:NSLocalizedString(@"The password is too short (minimum %d characters).\n", nil), password_length]]; } - + if (![password2 isEqualToString:password]) { [errors appendString:NSLocalizedString(@"The passwords are different.\n", nil)]; } - + NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", @".+@.+\\.[A-Za-z]{2}[A-Za-z]*"]; if(![emailTest evaluateWithObject:email]) { [errors appendString:NSLocalizedString(@"The email is invalid.\n", nil)]; @@ -865,14 +865,14 @@ static UICompositeViewDescription *compositeDescription = nil; if( [url rangeOfString:@"://"].location == NSNotFound ) url = [NSString stringWithFormat:@"http://%@", url]; - [LinphoneLogger log:LinphoneLoggerLog format:@"Should use remote provisioning URL %@", url]; + LOGI(@"Should use remote provisioning URL %@", url); linphone_core_set_provisioning_uri([LinphoneManager getLc], [url UTF8String]); [waitView setHidden:false]; [[LinphoneManager instance] resetLinphoneCore]; } } else { - [LinphoneLogger log:LinphoneLoggerLog format:@"Canceled remote provisioning"]; + LOGI(@"Canceled remote provisioning"); } } @@ -929,13 +929,13 @@ static UICompositeViewDescription *compositeDescription = nil; [UIView setAnimationDuration:duration]; [UIView setAnimationCurve:curve]; [UIView setAnimationBeginsFromCurrentState:TRUE]; - + // Move view UIEdgeInsets inset = {0, 0, 0, 0}; [contentView setContentInset:inset]; [contentView setScrollIndicatorInsets:inset]; [contentView setShowsVerticalScrollIndicator:FALSE]; - + [UIView commitAnimations]; } @@ -948,14 +948,14 @@ static UICompositeViewDescription *compositeDescription = nil; [UIView setAnimationDuration:duration]; [UIView setAnimationCurve:curve]; [UIView setAnimationBeginsFromCurrentState:TRUE]; - + if(([[UIDevice currentDevice].systemVersion floatValue] < 8) && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { int width = endFrame.size.height; endFrame.size.height = endFrame.size.width; endFrame.size.width = width; } - + // Change inset { UIEdgeInsets inset = {0,0,0,0}; @@ -965,7 +965,7 @@ static UICompositeViewDescription *compositeDescription = nil; CGPoint gPos = [contentView convertPoint:pos toView:[UIApplication sharedApplication].keyWindow.rootViewController.view]; // Bypass IOS bug on landscape mode inset.bottom = -(rect.size.height - gPos.y - endFrame.size.height); if(inset.bottom < 0) inset.bottom = 0; - + [contentView setContentInset:inset]; [contentView setScrollIndicatorInsets:inset]; CGRect fieldFrame = activeTextField.frame; @@ -980,7 +980,7 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark - XMLRPCConnectionDelegate Functions - (void)request:(XMLRPCRequest *)request didReceiveResponse:(XMLRPCResponse *)response { - [LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC %@: %@", [request method], [response body]]; + LOGI(@"XMLRPC %@: %@", [request method], [response body]); [waitView setHidden:true]; if ([response isFault]) { NSString *errorString = [NSString stringWithFormat:NSLocalizedString(@"Communication issue (%@)", nil), [response faultString]]; @@ -1059,11 +1059,11 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)request:(XMLRPCRequest *)request didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { - + } - (void)request:(XMLRPCRequest *)request didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { - + } #pragma mark - TPMultiLayoutViewController Functions From 5c02755992ac6f626bb65b6e8a873d30ac813cd0 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 17 Apr 2015 15:11:05 +0200 Subject: [PATCH 11/29] continue --- Classes/InAppProductsCell.xib | 8 +- Classes/InAppProductsManager.h | 6 +- Classes/InAppProductsManager.m | 89 +++++++++++++++++----- Classes/InAppProductsTableViewController.m | 6 +- Classes/InAppProductsViewController.xib | 2 +- Resources/linphonerc-factory | 3 +- Resources/linphonerc-factory~ipad | 2 + 7 files changed, 88 insertions(+), 28 deletions(-) diff --git a/Classes/InAppProductsCell.xib b/Classes/InAppProductsCell.xib index 135e74bb1..73791c7a4 100644 --- a/Classes/InAppProductsCell.xib +++ b/Classes/InAppProductsCell.xib @@ -21,28 +21,28 @@ - + diff --git a/Classes/InAppProductsManager.h b/Classes/InAppProductsManager.h index 352e7ae79..92c244ac2 100644 --- a/Classes/InAppProductsManager.h +++ b/Classes/InAppProductsManager.h @@ -30,14 +30,16 @@ extern NSString *const kLinphoneIAPurchaseNotification; #define IAPPurchaseSucceeded @"IAPPurchaseSucceeded" #define IAPRestoreFailed @"IAPRestoreFailed" #define IAPRestoreSucceeded @"IAPRestoreSucceeded" +#define IAPReceiptFailed @"IAPReceiptFailed" +#define IAPReceiptSucceeded @"IAPReceiptSucceeded" + typedef NSString* IAPPurchaseNotificationStatus; @property (nonatomic, retain) IAPPurchaseNotificationStatus status; @property (nonatomic, copy) NSString *errlast; @property (nonatomic, strong) NSMutableArray *productsAvailable; -@property (nonatomic, strong) NSMutableArray *productsPurchased; -@property (nonatomic, strong) NSMutableArray *productsRestored; +@property (nonatomic, strong) NSMutableArray *productsIDPurchased; - (void)loadProducts; - (BOOL)isPurchased:(SKProduct*)product; diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index 9fc3fc8a6..c8a5f97cf 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -19,6 +19,7 @@ #import "InAppProductsManager.h" #import "Utils.h" +#import "LinphoneManager.h" NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotification"; @@ -29,6 +30,7 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati - (instancetype)init { if ((self = [super init]) != nil) { ready = false; + [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; [self loadProducts]; } return self; @@ -40,6 +42,7 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati } //TODO: move this list elsewhere NSArray * list = [[[NSArray alloc] initWithArray:@[@"test.auto_renew_7days", @"test.non_renew", @"test.one_time", @"test.auto_renew_1month_withfree"]] autorelease]; + _productsIDPurchased = [[NSMutableArray alloc] initWithCapacity:0]; SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithArray:list]]; @@ -49,7 +52,7 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { - _productsAvailable= [[NSMutableArray arrayWithArray: response.products] retain]; + _productsAvailable = [[NSMutableArray arrayWithArray: response.products] retain]; LOGI(@"Found %lu products available", (unsigned long)_productsAvailable.count); @@ -64,8 +67,8 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati } - (BOOL)isPurchased:(SKProduct*)product { - for (SKProduct *prod in _productsPurchased) { - if (prod == product) { + for (NSString *prod in _productsIDPurchased) { + if ([prod isEqual: product.productIdentifier]) { bool isBought = true; LOGE(@"%@ is %s bought.", product.localizedTitle, isBought?"":"NOT"); return isBought; @@ -87,11 +90,55 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati -(void)restore { LOGI(@"Restoring user purchases..."); - if (! [SKPaymentQueue canMakePayments]) { LOGF(@"Not allowed to do in app purchase!!!"); } - _productsRestored = [[NSMutableArray alloc] initWithCapacity:0]; + if (! [SKPaymentQueue canMakePayments]) { + LOGF(@"Not allowed to do in app purchase!!!"); + } [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; } +- (void)checkReceipt: (SKPaymentTransaction*)transaction { + NSData *receiptData = nil; + NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; + // Test whether the receipt is present at the above URL + if(![[NSFileManager defaultManager] fileExistsAtPath:[receiptURL path]]) { + receiptData = [NSData dataWithContentsOfURL:receiptURL]; + } else { + LOGI(@"Could not find any receipt in application, using the transaction one!"); + receiptData = transaction.transactionReceipt; + } + + // We must validate the receipt on our server + NSURL *storeURL = [NSURL URLWithString:[[LinphoneManager instance] lpConfigStringForKey:@"inapp_receipt_validation_url"]]; + NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL]; + [storeRequest setHTTPMethod:@"POST"]; + [storeRequest setHTTPBody:receiptData]; + + NSOperationQueue *queue = [[NSOperationQueue alloc] init]; + [NSURLConnection sendAsynchronousRequest:storeRequest + queue:queue + completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { + if (data == nil) { + LOGE(@"Server replied nothing, aborting now."); + } else if (connectionError) { + LOGE(@"Could not verify the receipt, aborting now: (%d) %@.", connectionError.code, connectionError); + } else { + NSError *jsonError; + NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError]; + if (jsonError == nil) { + // Hourray, we can finally unlock purchase stuff in app! + LOGI(@"In apps purchased are %@", jsonResponse); + LOGE(@"To do: [_productsIDPurchased addObject:transaction.payment.productIdentifier];"); + [self postNotificationforStatus:IAPReceiptSucceeded]; + return; + } else { + LOGE(@"Impossible to parse receipt JSON response, aborting now because of %@: %@.", jsonError, [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]); + } + } + // Something failed when checking the receipt + [self postNotificationforStatus:IAPReceiptFailed]; + }]; +} + - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { for(SKPaymentTransaction * transaction in transactions) { switch (transaction.transactionState) { @@ -99,9 +146,24 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati break; case SKPaymentTransactionStatePurchased: case SKPaymentTransactionStateRestored: - [_productsPurchased addObject:transaction]; + [self checkReceipt: transaction]; [self completeTransaction:transaction forStatus:IAPPurchaseSucceeded]; break; + +// case SKPaymentTransactionStatePurchasing: +// break; +// case SKPaymentTransactionStateDeferred: +// [self transactionDeferred:transaction]; +// break; +// case SKPaymentTransactionStatePurchased: +// [self completeTransaction:transaction]; +// break; +// case SKPaymentTransactionStateRestored: +// [self restoreTransaction:transaction]; +// break; +// case SKPaymentTransactionStateFailed: +// [self failedTransaction:transaction]; +// break; default: _errlast = [NSString stringWithFormat:@"Purchase of %@ failed.",transaction.payment.productIdentifier]; [self completeTransaction:transaction forStatus:IAPPurchaseFailed]; @@ -112,7 +174,7 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati - (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray *)transactions { for(SKPaymentTransaction * transaction in transactions) { - NSLog(@"%@ was removed from the payment queue.", transaction.payment.productIdentifier); + LOGI(@"%@ was removed from the payment queue.", transaction.payment.productIdentifier); } } @@ -123,19 +185,8 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati } } -- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue -{ +- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue { LOGI(@"All restorable transactions have been processed by the payment queue."); -// for (SKPayment *payment in queue) { -// [queue transactions] -// [_productsRestored addObject:payment.productIdentifier]; -// } - - for (SKPaymentTransaction *transaction in queue.transactions) { - NSString *productID = transaction.payment.productIdentifier; - [_productsRestored addObject:productID]; - NSLog (@"product id is %@" , productID); - } } -(void)postNotificationforStatus:(IAPPurchaseNotificationStatus)status { diff --git a/Classes/InAppProductsTableViewController.m b/Classes/InAppProductsTableViewController.m index ec5d4362d..59f6521cf 100644 --- a/Classes/InAppProductsTableViewController.m +++ b/Classes/InAppProductsTableViewController.m @@ -25,6 +25,8 @@ selector:@selector(onIAPPurchaseNotification:) name:kLinphoneIAPurchaseNotification object:nil]; + + [[self tableView] reloadData]; } - (void)viewWillDisappear:(BOOL)animated { @@ -36,7 +38,9 @@ } - (void)onIAPPurchaseNotification:(NSNotification*)notif { - if ([[iapm status] isEqual: IAPAvailableSucceeded]) { + if ([[iapm status] isEqual: IAPAvailableSucceeded] + || [[iapm status] isEqualToString: IAPRestoreSucceeded] + || [[iapm status] isEqualToString: IAPPurchaseSucceeded]) { [[self tableView] reloadData]; } } diff --git a/Classes/InAppProductsViewController.xib b/Classes/InAppProductsViewController.xib index e90f0bf64..97ae28b44 100644 --- a/Classes/InAppProductsViewController.xib +++ b/Classes/InAppProductsViewController.xib @@ -27,7 +27,7 @@ @@ -154,11 +155,11 @@ - + - + @@ -192,7 +193,7 @@ - + @@ -202,7 +203,7 @@ - + @@ -212,7 +213,7 @@ - + @@ -222,7 +223,7 @@ - + @@ -381,11 +382,11 @@ - + - + @@ -412,7 +413,7 @@ - + @@ -422,7 +423,7 @@ - + @@ -434,7 +435,7 @@ - + diff --git a/Classes/InAppProductsCell.m b/Classes/InAppProductsCell.m index 229e7751f..6062261d6 100644 --- a/Classes/InAppProductsCell.m +++ b/Classes/InAppProductsCell.m @@ -33,6 +33,7 @@ [_pdescription setText: [prod localizedDescription]]; [_pprice setText: formattedPrice]; [_ppurchased setOn: [[[LinphoneManager instance] iapManager] isPurchasedWithID:prod.productIdentifier]]; + _productID = prod.productIdentifier; } - (id)initWithIdentifier:(NSString*)identifier maximized:(bool)maximized { if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) != nil) { diff --git a/Classes/InAppProductsManager.h b/Classes/InAppProductsManager.h index 68f59e8ab..95197463c 100644 --- a/Classes/InAppProductsManager.h +++ b/Classes/InAppProductsManager.h @@ -20,8 +20,13 @@ #import #import +#import + extern NSString *const kLinphoneIAPurchaseNotification; +@interface InAppProductsXMLRPCDelegate : NSObject +@end + @interface InAppProductsManager : NSObject #define IAPAvailableSucceeded @"IAPAvailableSucceeded" @@ -35,6 +40,9 @@ extern NSString *const kLinphoneIAPurchaseNotification; typedef NSString* IAPPurchaseNotificationStatus; +// needed because request:didFailWithError method is already used by SKProductsRequestDelegate... +@property (nonatomic, retain) InAppProductsXMLRPCDelegate *xmlrpc; + @property (nonatomic, retain) IAPPurchaseNotificationStatus status; @property (nonatomic, copy) NSString *errlast; @@ -45,5 +53,8 @@ typedef NSString* IAPPurchaseNotificationStatus; - (BOOL)isPurchasedWithID:(NSString*)productId; - (void)purchaseWithID:(NSString*)productId; - (void)restore; +- (void)retrievePurchases; +- (void)XMLRPCRequest:(XMLRPCRequest *)request didReceiveResponse:(XMLRPCResponse *)response; +- (void)XMLRPCRequest:(XMLRPCRequest *)request didFailWithError:(NSError *)error; @end diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index b68f453e9..7a1af2131 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -18,27 +18,64 @@ */ #import "InAppProductsManager.h" + +#import +#import +#import +#import + #import "Utils.h" #import "LinphoneManager.h" NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotification"; + +@implementation InAppProductsXMLRPCDelegate { + InAppProductsManager *iapm; +} + +#pragma mark - XMLRPCConnectionDelegate Functions + +- (void)request:(XMLRPCRequest *)request didReceiveResponse:(XMLRPCResponse *)response { + [[[LinphoneManager instance] iapManager] XMLRPCRequest:request didReceiveResponse:response]; +} + +- (void)request:(XMLRPCRequest *)request didFailWithError:(NSError *)error { + [[[LinphoneManager instance] iapManager] XMLRPCRequest:request didFailWithError:error]; +} + +- (BOOL)request:(XMLRPCRequest *)request canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { + return FALSE; +} + +- (void)request:(XMLRPCRequest *)request didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { + +} + +- (void)request:(XMLRPCRequest *)request didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { + +} + +@end + @implementation InAppProductsManager { } - (instancetype)init { if ((self = [super init]) != nil) { + _xmlrpc = [[InAppProductsXMLRPCDelegate alloc] init]; [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; [self loadProducts]; } return self; } +#define INAPP_AVAIL() ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) && ([SKPaymentQueue canMakePayments]) + - (void)loadProducts { - if (! [SKPaymentQueue canMakePayments]) { - return; - } - NSArray * list = [[[[LinphoneManager instance] lpConfigStringForKey:@"inapp_products_list"] stringByReplacingOccurrencesOfString:@" " withString:@""] componentsSeparatedByString:@","]; + if (!INAPP_AVAIL()) return; + + NSArray * list = [[[[LinphoneManager instance] lpConfigStringForKey:@"products_list" forSection:@"in_app_purchase"] stringByReplacingOccurrencesOfString:@" " withString:@""] componentsSeparatedByString:@","]; _productsIDPurchased = [[NSMutableArray alloc] initWithCapacity:0]; @@ -75,9 +112,10 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati return false; } -- (void)purchaseWithID:(NSString *)productId { +- (void)purchaseWithID:(NSString *)productID { + LOGI(@"Trying to purchase %@", productID); for (SKProduct *product in _productsAvailable) { - if ([product.productIdentifier compare:productId options:NSLiteralSearch] == NSOrderedSame) { + if ([product.productIdentifier compare:productID options:NSLiteralSearch] == NSOrderedSame) { SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product]; [[SKPaymentQueue defaultQueue] addPayment:payment]; return; @@ -88,53 +126,49 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati -(void)restore { LOGI(@"Restoring user purchases..."); - if (! [SKPaymentQueue canMakePayments]) { - LOGF(@"Not allowed to do in app purchase!!!"); - } [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; } +static SKRequest* req = nil; + +- (void)requestDidFinish:(SKRequest *)request { + if (req == request) { + LOGI(@"Got receipt"); + [self checkReceipt:nil]; + } +} + +- (void)request:(SKRequest *)skrequest didFailWithError:(NSError *)error { + LOGE(@"Did not get receipt: %@", error); + [self setStatus:IAPReceiptFailed]; +} + - (void)checkReceipt: (SKPaymentTransaction*)transaction { NSData *receiptData = nil; NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; // Test whether the receipt is present at the above URL if(![[NSFileManager defaultManager] fileExistsAtPath:[receiptURL path]]) { - receiptData = [NSData dataWithContentsOfURL:receiptURL]; + receiptData = [NSData dataWithContentsOfURL:receiptURL]; + LOGI(@"Found appstore receipt containing: %@", receiptData); + } else if (req == nil) { + // We are probably in sandbox environment, trying to retrieve it... + req = [[SKReceiptRefreshRequest alloc] init]; + LOGI(@"Receipt not found yet, trying to retrieve it..."); + req.delegate = self; + [req start]; } else { - LOGI(@"Could not find any receipt in application, using the transaction one!"); - receiptData = transaction.transactionReceipt; + LOGF(@"No receipt found"); } // We must validate the receipt on our server - NSURL *storeURL = [NSURL URLWithString:[[LinphoneManager instance] lpConfigStringForKey:@"inapp_receipt_validation_url"]]; - NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL]; - [storeRequest setHTTPMethod:@"POST"]; - [storeRequest setHTTPBody:receiptData]; + NSURL *URL = [NSURL URLWithString:[[LinphoneManager instance] lpConfigStringForKey:@"receipt_validation_url" forSection:@"in_app_purchase"]]; - NSOperationQueue *queue = [[NSOperationQueue alloc] init]; - [NSURLConnection sendAsynchronousRequest:storeRequest - queue:queue - completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { - if (data == nil) { - LOGE(@"Server replied nothing, aborting now."); - } else if (connectionError) { - LOGE(@"Could not verify the receipt, aborting now: (%d) %@.", connectionError.code, connectionError); - } else { - NSError *jsonError; - NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError]; - if (jsonError == nil) { - // Hourray, we can finally unlock purchase stuff in app! - LOGI(@"In apps purchased are %@", jsonResponse); - LOGE(@"To do: [_productsIDPurchased addObject:transaction.payment.productIdentifier];"); - [self postNotificationforStatus:IAPReceiptSucceeded]; - return; - } else { - LOGE(@"Impossible to parse receipt JSON response, aborting now because of %@: %@.", jsonError, [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]); - } - } - // Something failed when checking the receipt - [self postNotificationforStatus:IAPReceiptFailed]; - }]; + XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL]; + [request setMethod: @"in_app_receipt_validation" withParameters:[NSArray arrayWithObjects:@"ios", receiptData, nil]]; + XMLRPCConnectionManager *manager = [XMLRPCConnectionManager sharedManager]; + [manager spawnConnectionWithXMLRPCRequest: request delegate: self.xmlrpc]; + + [request release]; } - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { @@ -147,23 +181,12 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati [self checkReceipt: transaction]; [self completeTransaction:transaction forStatus:IAPPurchaseSucceeded]; break; - -// case SKPaymentTransactionStatePurchasing: -// break; -// case SKPaymentTransactionStateDeferred: -// [self transactionDeferred:transaction]; -// break; -// case SKPaymentTransactionStatePurchased: -// [self completeTransaction:transaction]; -// break; -// case SKPaymentTransactionStateRestored: -// [self restoreTransaction:transaction]; -// break; -// case SKPaymentTransactionStateFailed: -// [self failedTransaction:transaction]; -// break; - default: + case SKPaymentTransactionStateDeferred: + //waiting for parent approval + break; + case SKPaymentTransactionStateFailed: _errlast = [NSString stringWithFormat:@"Purchase of %@ failed.",transaction.payment.productIdentifier]; + LOGE(@"%@", _errlast); [self completeTransaction:transaction forStatus:IAPPurchaseFailed]; break; } @@ -204,4 +227,57 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; } +- (void)retrievePurchases { + [self checkReceipt:nil]; +} + +- (void)XMLRPCRequest:(XMLRPCRequest *)request didReceiveResponse:(XMLRPCResponse *)response { + LOGI(@"XMLRPC %@: %@", [request method], [response body]); + // [waitView setHidden:true]; + if ([response isFault]) { + LOGE(@"Communication issue (%@)", [response faultString]); + // NSString *errorString = [NSString stringWithFormat:NSLocalizedString(@"Communication issue (%@)", nil), [response faultString]]; + // UIAlertView* errorView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Communication issue",nil) + // message:errorString + // delegate:nil + // cancelButtonTitle:NSLocalizedString(@"Continue",nil) + // otherButtonTitles:nil,nil]; + // [errorView show]; + // [errorView release]; + } else if([response object] != nil) { + //Don't handle if not object: HTTP/Communication Error + if([[request method] isEqualToString:@"check_account"]) { + if([response object] == [NSNumber numberWithInt:0]) { + // UIAlertView* errorView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Check issue",nil) + // message:NSLocalizedString(@"Username already exists", nil) + // delegate:nil + // cancelButtonTitle:NSLocalizedString(@"Continue",nil) + // otherButtonTitles:nil,nil]; + // [errorView show]; + // [errorView release]; + [self.productsIDPurchased addObject:@"test.one_time"]; + [self postNotificationforStatus:IAPReceiptSucceeded]; + return; + } + } + } + [self postNotificationforStatus:IAPReceiptFailed]; +} + +- (void)XMLRPCRequest:(XMLRPCRequest *)request didFailWithError:(NSError *)error { + LOGE(@"Communication issue (%@)", [error localizedDescription]); + [self.productsIDPurchased addObject:@"test.one_time"]; + // NSString *errorString = [NSString stringWithFormat:NSLocalizedString(@"Communication issue (%@)", nil), [error localizedDescription]]; + // UIAlertView* errorView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Communication issue", nil) + // message:errorString + // delegate:nil + // cancelButtonTitle:NSLocalizedString(@"Continue", nil) + // otherButtonTitles:nil,nil]; + // [errorView show]; + // [errorView release]; + // [waitView setHidden:true]; + + [self postNotificationforStatus:IAPReceiptFailed]; +} @end + diff --git a/Classes/InAppProductsTableViewController.m b/Classes/InAppProductsTableViewController.m index a45fdbcd8..1e046d47c 100644 --- a/Classes/InAppProductsTableViewController.m +++ b/Classes/InAppProductsTableViewController.m @@ -92,7 +92,6 @@ [alert release]; } else { //try to purchase item, and if successfull change the switch - LOGI(@"Trying to purchase %@", cell.productID); [[[LinphoneManager instance] iapManager] purchaseWithID: cell.productID]; } } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index ff2f18203..af6c4b5c1 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1370,6 +1370,8 @@ static LinphoneCoreVTable linphonec_vtable = { } linphone_core_enable_video(theLinphoneCore, FALSE, FALSE); } + // Retrieve InApp purchases + [_iapManager retrievePurchases]; LOGW(@"Linphone [%s] started on [%s]", linphone_core_get_version(), [[UIDevice currentDevice].model cStringUsingEncoding:[NSString defaultCStringEncoding]]); @@ -2257,5 +2259,7 @@ static void audioRouteChangeListenerCallback ( } } +#pragma InApp Purchase + @end diff --git a/Classes/WizardViewController.m b/Classes/WizardViewController.m index 8e270c372..36a4b4aa1 100644 --- a/Classes/WizardViewController.m +++ b/Classes/WizardViewController.m @@ -733,20 +733,23 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)inAppPurchaseNotification: (NSNotification*)notification { InAppProductsManager *iapm = [[LinphoneManager instance] iapManager]; - if ([iapm isPurchasedWithID:[[LinphoneManager instance] lpConfigStringForKey:@"inapp_paid_account_id" forSection:@"wizard"]]) { - nextView = createAccountView; - [self loadWizardConfig:@"wizard_linphone_create.rc"]; + if ([iapm isPurchasedWithID:[[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"]]) { + [self onPurchaseAccountClick:self]; } } - (IBAction)onPurchaseAccountClick:(id)sender { InAppProductsManager *iapm = [[LinphoneManager instance] iapManager]; //if has already purchased, continue - if (false) { - nextView = createAccountView; - [self loadWizardConfig:@"wizard_linphone_create.rc"]; + if ([iapm isPurchasedWithID:[[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"]]) { + NSString *username = [WizardViewController findTextField:ViewElement_Username view:contentView].text; + NSString *password = [WizardViewController findTextField:ViewElement_Password view:contentView].text; + NSString *domain = [WizardViewController findTextField:ViewElement_Domain view:contentView].text; + NSString *transport = [self.transportChooser titleForSegmentAtIndex:self.transportChooser.selectedSegmentIndex]; + + [self verificationSignInWithUsername:username password:password domain:domain withTransport:transport]; } else { - [iapm purchaseWithID: [[LinphoneManager instance] lpConfigStringForKey:@"inapp_paid_account_id" forSection:@"wizard"]]; + [iapm purchaseWithID: [[LinphoneManager instance] lpConfigStringForKey:@"paid_account_id" forSection:@"in_app_purchase"]]; } } diff --git a/Resources/linphonerc-factory b/Resources/linphonerc-factory index 7c86ff681..9d20c530c 100644 --- a/Resources/linphonerc-factory +++ b/Resources/linphonerc-factory @@ -47,7 +47,6 @@ transport=tls sharing_server=https://www.linphone.org:444/upload.php ice=1 stun=stun.linphone.org -inapp_paid_account_id = test.auto_renew_7days [video] display_filter_auto_rotate=0 @@ -55,5 +54,9 @@ display_filter_auto_rotate=0 [app] #contact_display_username_only=1 #contact_filter_on_default_domain=1 -inapp_receipt_validation_url = https://linphone.org/inapp/veriyReceipt -inapp_products_list = test.auto_renew_7days, test.non_renew, test.one_time, test.auto_renew_1month_withfree + +[in_app_purchase] +enabled = 1 +paid_account_id = test.auto_renew_7days +receipt_validation_url = https://www.linphone.org/inapp.php +products_list = test.auto_renew_7days, test.non_renew, test.one_time, test.auto_renew_1month_withfree diff --git a/Resources/linphonerc-factory~ipad b/Resources/linphonerc-factory~ipad index afc14fc79..aa3a99255 100644 --- a/Resources/linphonerc-factory~ipad +++ b/Resources/linphonerc-factory~ipad @@ -47,11 +47,12 @@ transport=tls sharing_server=https://www.linphone.org:444/upload.php ice=1 stun=stun.linphone.org -inapp_paid_account_id = test.auto_renew_7days [video] display_filter_auto_rotate=0 -[app] -inapp_receipt_validation_url = https://linphone.org/inapp/veriyReceipt -inapp_products_list = test.auto_renew_7days, test.non_renew, test.one_time, test.auto_renew_1month_withfree \ No newline at end of file +[in_app_purchase] +enabled = 1 +paid_account_id = test.auto_renew_7days +receipt_validation_url = https://www.linphone.org/inapp.php +products_list = test.auto_renew_7days, test.non_renew, test.one_time, test.auto_renew_1month_withfree \ No newline at end of file diff --git a/linphone-Info.plist b/linphone-Info.plist index 964a1563d..57479d407 100644 --- a/linphone-Info.plist +++ b/linphone-Info.plist @@ -53,7 +53,7 @@ CFBundleVersion - 2 + 4 LSRequiresIPhoneOS UIApplicationExitsOnSuspend diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index 12f7f743a..c340b59ba 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -936,7 +936,6 @@ 1D3623250D0F684500981E51 /* LinphoneAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LinphoneAppDelegate.m; sourceTree = ""; }; 1D6058910D05DD3D006BFB54 /* linphone.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = linphone.app; sourceTree = BUILT_PRODUCTS_DIR; }; 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; - 1FE76362DA6217E7341ED1DF /* libPods-KifTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-KifTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 220FAD2910765B400068D98F /* libgsm.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgsm.a; path = "liblinphone-sdk/apple-darwin/lib/libgsm.a"; sourceTree = ""; }; 220FAD2C10765B400068D98F /* libortp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libortp.a; path = "liblinphone-sdk/apple-darwin/lib/libortp.a"; sourceTree = ""; }; 220FAD2F10765B400068D98F /* libspeex.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libspeex.a; path = "liblinphone-sdk/apple-darwin/lib/libspeex.a"; sourceTree = ""; }; @@ -2310,7 +2309,6 @@ 22509041196BD902007863F6 /* libopenh264.a */, 22AF73C11754C0D000BE8398 /* libopus.a */, 220FAD2C10765B400068D98F /* libortp.a */, - 1FE76362DA6217E7341ED1DF /* libPods-KifTests.a */, 57B0E35F173C010400A476B8 /* libpolarssl.a */, F0BB8C34193624C800974404 /* libresolv.9.dylib */, 22D1B68012A3E0BE001AE361 /* libresolv.dylib */, @@ -5336,6 +5334,7 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/liblinphone-sdk/apple-darwin/include", + "$(SRCROOT)/Classes/Utils/XMLRPC/", ); INFOPLIST_FILE = KifTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -5380,6 +5379,7 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/liblinphone-sdk/apple-darwin/include", + "$(SRCROOT)/Classes/Utils/XMLRPC/", ); INFOPLIST_FILE = KifTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -5424,6 +5424,7 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/liblinphone-sdk/apple-darwin/include", + "$(SRCROOT)/Classes/Utils/XMLRPC/", ); INFOPLIST_FILE = KifTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -5468,6 +5469,7 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/liblinphone-sdk/apple-darwin/include", + "$(SRCROOT)/Classes/Utils/XMLRPC/", ); INFOPLIST_FILE = KifTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; From 7228feec683e1db7993a9e65a8d52d91c6738ead Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Wed, 22 Apr 2015 11:47:02 +0200 Subject: [PATCH 15/29] continue --- Classes/InAppProductsManager.h | 2 ++ Classes/InAppProductsManager.m | 53 +++++++++++++++++++------------ Classes/PhoneMainView.m | 3 +- Resources/linphonerc-factory | 8 ++--- Resources/linphonerc-factory~ipad | 8 ++--- 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/Classes/InAppProductsManager.h b/Classes/InAppProductsManager.h index 95197463c..9660fa51f 100644 --- a/Classes/InAppProductsManager.h +++ b/Classes/InAppProductsManager.h @@ -29,6 +29,8 @@ extern NSString *const kLinphoneIAPurchaseNotification; @interface InAppProductsManager : NSObject +// startup status, manager is not ready yet. +#define IAPNotReadyYet @"IAPNotReadyYet" #define IAPAvailableSucceeded @"IAPAvailableSucceeded" #define IAPAvailableFailed @"IAPAvailableFailed" #define IAPPurchaseFailed @"IAPPurchaseFailed" diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index 7a1af2131..a530bcd6d 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -64,6 +64,7 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati - (instancetype)init { if ((self = [super init]) != nil) { _xmlrpc = [[InAppProductsXMLRPCDelegate alloc] init]; + _status = IAPNotReadyYet; [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; [self loadProducts]; } @@ -79,8 +80,7 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati _productsIDPurchased = [[NSMutableArray alloc] initWithCapacity:0]; - SKProductsRequest *productsRequest = [[SKProductsRequest alloc] - initWithProductIdentifiers:[NSSet setWithArray:list]]; + SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithArray:list]]; productsRequest.delegate = self; [productsRequest start]; } @@ -121,6 +121,7 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati return; } } + LOGE(@"Impossible to find product with ID %@...", productID); [self postNotificationforStatus:IAPPurchaseFailed]; } @@ -129,17 +130,24 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; } -static SKRequest* req = nil; - - (void)requestDidFinish:(SKRequest *)request { - if (req == request) { - LOGI(@"Got receipt"); - [self checkReceipt:nil]; + if([request isKindOfClass:[SKReceiptRefreshRequest class]]) { + NSURL *receiptUrl = [[NSBundle mainBundle] appStoreReceiptURL]; + if ([[NSFileManager defaultManager] fileExistsAtPath:[receiptUrl path]]) { + LOGI(@"App Receipt exists"); + [self checkReceipt:nil]; + } else { + LOGE(@"Receipt request done but there is no receipt"); + + // This can happen if the user cancels the login screen for the store. + // If we get here it means there is no receipt and an attempt to get it failed because the user cancelled the login. + //[self trackFailedAttempt]; + } } } - (void)request:(SKRequest *)skrequest didFailWithError:(NSError *)error { - LOGE(@"Did not get receipt: %@", error); + LOGE(@"Did not get receipt: %@", error.localizedDescription); [self setStatus:IAPReceiptFailed]; } @@ -147,27 +155,32 @@ static SKRequest* req = nil; NSData *receiptData = nil; NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; // Test whether the receipt is present at the above URL - if(![[NSFileManager defaultManager] fileExistsAtPath:[receiptURL path]]) { + if([[NSFileManager defaultManager] fileExistsAtPath:[receiptURL path]]) { receiptData = [NSData dataWithContentsOfURL:receiptURL]; LOGI(@"Found appstore receipt containing: %@", receiptData); - } else if (req == nil) { + } else { // We are probably in sandbox environment, trying to retrieve it... - req = [[SKReceiptRefreshRequest alloc] init]; + SKRequest* req = [[SKReceiptRefreshRequest alloc] init]; LOGI(@"Receipt not found yet, trying to retrieve it..."); req.delegate = self; [req start]; - } else { - LOGF(@"No receipt found"); + return; } // We must validate the receipt on our server NSURL *URL = [NSURL URLWithString:[[LinphoneManager instance] lpConfigStringForKey:@"receipt_validation_url" forSection:@"in_app_purchase"]]; XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL]; - [request setMethod: @"in_app_receipt_validation" withParameters:[NSArray arrayWithObjects:@"ios", receiptData, nil]]; + [request setMethod: @"create_account_from_in_app_purchase" withParameters:[NSArray arrayWithObjects: + @"toto@test.linphone.org", + @"toto", + receiptData, + @"", + @"apple", + nil]]; XMLRPCConnectionManager *manager = [XMLRPCConnectionManager sharedManager]; [manager spawnConnectionWithXMLRPCRequest: request delegate: self.xmlrpc]; - + LOGE(@"XMLRPC query %@: %@", [request method], [request body]); [request release]; } @@ -185,7 +198,7 @@ static SKRequest* req = nil; //waiting for parent approval break; case SKPaymentTransactionStateFailed: - _errlast = [NSString stringWithFormat:@"Purchase of %@ failed.",transaction.payment.productIdentifier]; + _errlast = [NSString stringWithFormat:@"Purchase of %@ failed: %@.",transaction.payment.productIdentifier,transaction.error.localizedDescription]; LOGE(@"%@", _errlast); [self completeTransaction:transaction forStatus:IAPPurchaseFailed]; break; @@ -228,11 +241,11 @@ static SKRequest* req = nil; } - (void)retrievePurchases { - [self checkReceipt:nil]; + LOGE(@"todo");//[self checkReceipt:nil]; } - (void)XMLRPCRequest:(XMLRPCRequest *)request didReceiveResponse:(XMLRPCResponse *)response { - LOGI(@"XMLRPC %@: %@", [request method], [response body]); + LOGI(@"XMLRPC response %@: %@", [request method], [response body]); // [waitView setHidden:true]; if ([response isFault]) { LOGE(@"Communication issue (%@)", [response faultString]); @@ -254,8 +267,7 @@ static SKRequest* req = nil; // cancelButtonTitle:NSLocalizedString(@"Continue",nil) // otherButtonTitles:nil,nil]; // [errorView show]; - // [errorView release]; - [self.productsIDPurchased addObject:@"test.one_time"]; + // [errorView release];! [self postNotificationforStatus:IAPReceiptSucceeded]; return; } @@ -266,7 +278,6 @@ static SKRequest* req = nil; - (void)XMLRPCRequest:(XMLRPCRequest *)request didFailWithError:(NSError *)error { LOGE(@"Communication issue (%@)", [error localizedDescription]); - [self.productsIDPurchased addObject:@"test.one_time"]; // NSString *errorString = [NSString stringWithFormat:NSLocalizedString(@"Communication issue (%@)", nil), [error localizedDescription]]; // UIAlertView* errorView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Communication issue", nil) // message:errorString diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index b8004a291..2abf1c10f 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -419,8 +419,7 @@ static RootViewManager* rootViewManagerInstance = nil; // Change to default view const MSList *list = linphone_core_get_proxy_config_list(core); if(list != NULL || ([lm lpConfigBoolForKey:@"hide_wizard_preference"] == true) || lm.isTesting) { - [self changeCurrentView: [InAppProductsViewController compositeViewDescription]]; - + [self changeCurrentView: [DialerViewController compositeViewDescription]]; } else { WizardViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[WizardViewController compositeViewDescription]], WizardViewController); if(controller != nil) { diff --git a/Resources/linphonerc-factory b/Resources/linphonerc-factory index 9d20c530c..cb5cdc956 100644 --- a/Resources/linphonerc-factory +++ b/Resources/linphonerc-factory @@ -56,7 +56,7 @@ display_filter_auto_rotate=0 #contact_filter_on_default_domain=1 [in_app_purchase] -enabled = 1 -paid_account_id = test.auto_renew_7days -receipt_validation_url = https://www.linphone.org/inapp.php -products_list = test.auto_renew_7days, test.non_renew, test.one_time, test.auto_renew_1month_withfree +enabled=1 +paid_account_id=test.auto_renew_7days +receipt_validation_url=https://www.linphone.org/inapp.php +products_list=test.auto_renew_7days,test.non_renew,test.one_time,test.auto_renew_1month_withfree diff --git a/Resources/linphonerc-factory~ipad b/Resources/linphonerc-factory~ipad index aa3a99255..3d307a79d 100644 --- a/Resources/linphonerc-factory~ipad +++ b/Resources/linphonerc-factory~ipad @@ -52,7 +52,7 @@ stun=stun.linphone.org display_filter_auto_rotate=0 [in_app_purchase] -enabled = 1 -paid_account_id = test.auto_renew_7days -receipt_validation_url = https://www.linphone.org/inapp.php -products_list = test.auto_renew_7days, test.non_renew, test.one_time, test.auto_renew_1month_withfree \ No newline at end of file +enabled=1 +paid_account_id=test.auto_renew_7days +receipt_validation_url=https://www.linphone.org/inapp.php +products_list=test.auto_renew_7days,test.non_renew,test.one_time,test.auto_renew_1month_withfree \ No newline at end of file From e22d65b898aa0fd52f3cf9807486733098cba1af Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 24 Apr 2015 15:57:48 +0200 Subject: [PATCH 16/29] continue --- Classes/InAppProductsManager.m | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index a530bcd6d..83e165dea 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -157,7 +157,7 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati // Test whether the receipt is present at the above URL if([[NSFileManager defaultManager] fileExistsAtPath:[receiptURL path]]) { receiptData = [NSData dataWithContentsOfURL:receiptURL]; - LOGI(@"Found appstore receipt containing: %@", receiptData); + LOGI(@"Found appstore receipt"); } else { // We are probably in sandbox environment, trying to retrieve it... SKRequest* req = [[SKReceiptRefreshRequest alloc] init]; @@ -171,10 +171,8 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati NSURL *URL = [NSURL URLWithString:[[LinphoneManager instance] lpConfigStringForKey:@"receipt_validation_url" forSection:@"in_app_purchase"]]; XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL]; - [request setMethod: @"create_account_from_in_app_purchase" withParameters:[NSArray arrayWithObjects: - @"toto@test.linphone.org", - @"toto", - receiptData, + [request setMethod: @"get_expiration_date" withParameters:[NSArray arrayWithObjects: + [receiptData base64EncodedStringWithOptions:0], @"", @"apple", nil]]; @@ -259,15 +257,8 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati // [errorView release]; } else if([response object] != nil) { //Don't handle if not object: HTTP/Communication Error - if([[request method] isEqualToString:@"check_account"]) { - if([response object] == [NSNumber numberWithInt:0]) { - // UIAlertView* errorView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Check issue",nil) - // message:NSLocalizedString(@"Username already exists", nil) - // delegate:nil - // cancelButtonTitle:NSLocalizedString(@"Continue",nil) - // otherButtonTitles:nil,nil]; - // [errorView show]; - // [errorView release];! + if([[request method] isEqualToString:@"get_expiration_date"]) { + if([response object] == [NSNumber numberWithInt:1]) { [self postNotificationforStatus:IAPReceiptSucceeded]; return; } From 3e275a95b119a77b692dfd55728972c353a060d9 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 27 Apr 2015 15:57:41 +0200 Subject: [PATCH 17/29] inapp: plug it in wizard and do not query server more than necessary --- Classes/Base.lproj/WizardViews.xib | 36 ++++++-- Classes/InAppProductsManager.h | 5 +- Classes/InAppProductsManager.m | 48 ++++++---- Classes/LinphoneManager.m | 2 +- Classes/Utils/Utils.h | 6 ++ Classes/Utils/Utils.m | 19 +++- Classes/WizardViewController.h | 3 + Classes/WizardViewController.m | 141 ++++++++++++++++++----------- 8 files changed, 174 insertions(+), 86 deletions(-) diff --git a/Classes/Base.lproj/WizardViews.xib b/Classes/Base.lproj/WizardViews.xib index 4a7bb5885..a410ace47 100644 --- a/Classes/Base.lproj/WizardViews.xib +++ b/Classes/Base.lproj/WizardViews.xib @@ -19,6 +19,8 @@ + + @@ -42,7 +44,7 @@ - + @@ -73,7 +75,7 @@ - + @@ -147,7 +149,7 @@ - + @@ -162,7 +164,7 @@ - + @@ -237,6 +239,22 @@ + @@ -249,7 +267,7 @@ - + @@ -309,7 +327,7 @@ - + @@ -389,7 +407,7 @@ - + @@ -450,7 +468,7 @@