forked from mirrors/linphone-iphone
Image saving now in image picker
This commit is contained in:
parent
385c828389
commit
7d5fbbbd11
5 changed files with 65 additions and 58 deletions
|
|
@ -20,7 +20,6 @@
|
|||
#import <MobileCoreServices/UTCoreTypes.h>
|
||||
#import <AVFoundation/AVCaptureDevice.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <Photos/Photos.h>
|
||||
#import "ImagePickerView.h"
|
||||
#import "PhoneMainView.h"
|
||||
|
||||
|
|
@ -166,9 +165,21 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
if (image == nil) {
|
||||
image = [info objectForKey:UIImagePickerControllerOriginalImage];
|
||||
}
|
||||
if (image != nil && imagePickerDelegate != nil) {
|
||||
[imagePickerDelegate imagePickerDelegateImage:image info:info];
|
||||
}
|
||||
if (image != nil) {
|
||||
if (![info objectForKey:UIImagePickerControllerReferenceURL]) {
|
||||
//Saving image. Supports picture only, no video
|
||||
//Maybe add a completion target to send the saved image to, like self, and we would call it manually if the image was not taken.
|
||||
UIImageWriteToSavedPhotosAlbum(image, self, @selector(savedImage:didFinishSavingWithError:contextInfo:), (__bridge void *)info);
|
||||
} else {
|
||||
[self savedImage:image didFinishSavingWithError:nil contextInfo:(__bridge void *)info];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)savedImage:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
|
||||
if (imagePickerDelegate != nil) {
|
||||
[imagePickerDelegate imagePickerDelegateImage:image info:(__bridge NSDictionary *)contextInfo];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
||||
|
|
|
|||
|
|
@ -226,6 +226,7 @@ typedef struct _LinphoneManagerSounds {
|
|||
@property (nonatomic, assign) BOOL speakerEnabled;
|
||||
@property (nonatomic, assign) BOOL bluetoothAvailable;
|
||||
@property (nonatomic, assign) BOOL bluetoothEnabled;
|
||||
@property (readonly) ALAssetsLibrary *photoLibrary;
|
||||
@property (readonly) NSString* contactSipField;
|
||||
@property (readonly,copy) NSString* contactFilter;
|
||||
@property (copy) void (^silentPushCompletion)(UIBackgroundFetchResult);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@
|
|||
</subviews>
|
||||
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</view>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" image="chat_read.png" id="aa2-Kl-c1H" userLabel="imdmIcon">
|
||||
<imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" image="chat_read.png" id="aa2-Kl-c1H" userLabel="imdmIcon">
|
||||
<rect key="frame" x="59" y="39" width="13" height="13"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Delivery failed">
|
||||
|
|
|
|||
|
|
@ -125,18 +125,18 @@
|
|||
|
||||
// taken from camera, must be saved to device first
|
||||
if (!url) {
|
||||
[LinphoneManager.instance.photoLibrary
|
||||
writeImageToSavedPhotosAlbum:image.CGImage
|
||||
orientation:(ALAssetOrientation)[image imageOrientation]
|
||||
completionBlock:^(NSURL *assetURL, NSError *error) {
|
||||
if (error) {
|
||||
LOGE(@"Cannot save image data downloaded [%@]", [error localizedDescription]);
|
||||
} else {
|
||||
LOGI(@"Image saved to [%@]", [assetURL absoluteString]);
|
||||
}
|
||||
[LinphoneManager.instance lpConfigSetString:assetURL.absoluteString forKey:@"avatar"];
|
||||
_avatarImage.image = [LinphoneUtils selfAvatar];
|
||||
}];
|
||||
__block NSURL *assetURL = nil;
|
||||
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
|
||||
[PHAssetChangeRequest creationRequestForAssetFromImage:image];
|
||||
} completionHandler:^(BOOL success, NSError *error) {
|
||||
if (success) {
|
||||
LOGI(@"Image saved to [%@]", [assetURL absoluteString]);
|
||||
} else {
|
||||
LOGE(@"Cannot save image data downloaded [%@]", [error localizedDescription]);
|
||||
}
|
||||
[LinphoneManager.instance lpConfigSetString:assetURL.absoluteString forKey:@"avatar"];
|
||||
_avatarImage.image = [LinphoneUtils selfAvatar];
|
||||
}];
|
||||
} else {
|
||||
[LinphoneManager.instance lpConfigSetString:url.absoluteString forKey:@"avatar"];
|
||||
_avatarImage.image = [LinphoneUtils selfAvatar];
|
||||
|
|
|
|||
|
|
@ -463,47 +463,42 @@
|
|||
}
|
||||
|
||||
+ (LinphoneAddress *)normalizeSipOrPhoneAddress:(NSString *)value {
|
||||
if (!value || [value isEqualToString:@""]) {
|
||||
return NULL;
|
||||
}
|
||||
LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(LC);
|
||||
const char *normvalue;
|
||||
if (linphone_proxy_config_is_phone_number(cfg, value.UTF8String)) {
|
||||
normvalue = linphone_proxy_config_normalize_phone_number(cfg, value.UTF8String);
|
||||
} else {
|
||||
normvalue = value.UTF8String;
|
||||
}
|
||||
LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri(cfg, normvalue);
|
||||
// first try to find a friend with the given address
|
||||
Contact *c = [FastAddressBook getContactWithAddress:addr];
|
||||
|
||||
if (c && c.friend) {
|
||||
LinphoneFriend *f = c.friend;
|
||||
const LinphonePresenceModel *m = f ? linphone_friend_get_presence_model_for_uri_or_tel(f, value.UTF8String) : NULL;
|
||||
const char *contact = m ? linphone_presence_model_get_contact(m) : NULL;
|
||||
if (contact) {
|
||||
LinphoneAddress *contact_addr = linphone_address_new(contact);
|
||||
if (contact_addr) {
|
||||
linphone_address_destroy(addr);
|
||||
return contact_addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// since user wants to escape plus, we assume it expects to have phone
|
||||
// numbers by default
|
||||
if (addr) {
|
||||
if (cfg || (linphone_proxy_config_get_dial_escape_plus(cfg))) {
|
||||
if (linphone_proxy_config_is_phone_number(cfg, normvalue)) {
|
||||
linphone_address_set_username(addr, normvalue);
|
||||
}
|
||||
} else {
|
||||
if (linphone_proxy_config_is_phone_number(cfg, value.UTF8String)) {
|
||||
linphone_address_set_username(addr, value.UTF8String);
|
||||
}
|
||||
}
|
||||
}
|
||||
return addr;
|
||||
if (!value || [value isEqualToString:@""])
|
||||
return NULL;
|
||||
|
||||
LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(LC);
|
||||
const char *normvalue;
|
||||
normvalue = linphone_proxy_config_is_phone_number(cfg, value.UTF8String)
|
||||
? linphone_proxy_config_normalize_phone_number(cfg, value.UTF8String)
|
||||
: value.UTF8String;
|
||||
|
||||
LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri(cfg, normvalue);
|
||||
// first try to find a friend with the given address
|
||||
Contact *c = [FastAddressBook getContactWithAddress:addr];
|
||||
|
||||
if (c && c.friend) {
|
||||
LinphoneFriend *f = c.friend;
|
||||
const LinphonePresenceModel *m = f
|
||||
? linphone_friend_get_presence_model_for_uri_or_tel(f, value.UTF8String)
|
||||
: NULL;
|
||||
const char *contact = m ? linphone_presence_model_get_contact(m) : NULL;
|
||||
if (contact) {
|
||||
LinphoneAddress *contact_addr = linphone_address_new(contact);
|
||||
if (contact_addr) {
|
||||
linphone_address_destroy(addr);
|
||||
return contact_addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// since user wants to escape plus, we assume it expects to have phone
|
||||
// numbers by default
|
||||
if (addr && cfg) {
|
||||
const char *username = linphone_proxy_config_get_dial_escape_plus(cfg) ? normvalue : value.UTF8String;
|
||||
if (linphone_proxy_config_is_phone_number(cfg, username))
|
||||
linphone_address_set_username(addr, username);
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue