Commit 67bf77bc authored by armin's avatar armin

Merge branch 'improveGalleryPickerCode' into 'master'

Improve gallery picker code

See merge request !218
parents c14008c9 719361ba
Pipeline #795 passed with stage
in 1 minute and 46 seconds
Subproject commit 1a8cb167fd08c9df87eed75e94af36a11453e48f Subproject commit 9ab892de72db4d211e6ad93e21f6e07cef3b412f
...@@ -163,7 +163,7 @@ ios{ ...@@ -163,7 +163,7 @@ ios{
QMAKE_ASSET_CATALOGS = $$PWD/ios/Images.xcassets QMAKE_ASSET_CATALOGS = $$PWD/ios/Images.xcassets
QMAKE_ASSET_CATALOGS_APP_ICON = "Appicon" QMAKE_ASSET_CATALOGS_APP_ICON = "Appicon"
QMAKE_IOS_DEPLOYMENT_TARGET = 10.0 QMAKE_IOS_DEPLOYMENT_TARGET = 11.0
QMAKE_APPLE_TARGETED_DEVICE_FAMILY = 1 QMAKE_APPLE_TARGETED_DEVICE_FAMILY = 1
PRODUCT_NAME = fairchat PRODUCT_NAME = fairchat
#PRODUCT_BUNDLE_IDENTIFIER = com.osalliance.RocketChatMobile #PRODUCT_BUNDLE_IDENTIFIER = com.osalliance.RocketChatMobile
......
...@@ -42,6 +42,7 @@ class IosGalleryPicker: public QObject ...@@ -42,6 +42,7 @@ class IosGalleryPicker: public QObject
void receiveFile( QString pFileUrl ); void receiveFile( QString pFileUrl );
private: private:
void openGalleryPicker();
QString mImagePath; QString mImagePath;
void *mDelegate; void *mDelegate;
......
...@@ -43,16 +43,22 @@ ...@@ -43,16 +43,22 @@
UIImage *orig = [info valueForKey:UIImagePickerControllerOriginalImage]; UIImage *orig = [info valueForKey:UIImagePickerControllerOriginalImage];
PHAsset *asset = [info valueForKey:UIImagePickerControllerPHAsset]; PHAsset *asset = [info valueForKey:UIImagePickerControllerPHAsset];
NSString *filename = [asset valueForKey:@"filename"];
QString qFilename = QString::fromNSString(filename); auto assetRes = [PHAssetResource assetResourcesForAsset:asset];
auto assetObj = [assetRes firstObject];
QStringList fileParts = qFilename.split(".");
QString fileExt = fileParts[fileParts.length()-1];
if(assetObj){
NSString * filename = [assetObj originalFilename ];
NSString *assetUti = [assetObj valueForKey:@"uniformTypeIdentifier"];
QString assetUtiStr = QString::fromNSString(assetUti);
QString qFilename = QString::fromNSString(filename);
NSData *imgData = nil; NSData *imgData = nil;
if(!fileExt.compare("png",Qt::CaseInsensitive)){ if(assetUtiStr == "public.png"){
imgData = UIImagePNGRepresentation(orig); imgData = UIImagePNGRepresentation(orig);
}else{ }else{
imgData = UIImageJPEGRepresentation(orig, 1.0); imgData = UIImageJPEGRepresentation(orig, 1.0);
...@@ -60,12 +66,16 @@ ...@@ -60,12 +66,16 @@
QByteArray qImgData = QByteArray::fromNSData(imgData); QByteArray qImgData = QByteArray::fromNSData(imgData);
QString path = QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation ); QString path = QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation );
path += "/"+QString::fromNSString(filename); path += "/"+qFilename;
QFile destFile(path); QFile destFile(path);
destFile.open(QFile::WriteOnly); destFile.open(QFile::WriteOnly);
if(destFile.write(qImgData)>0){ if(destFile.write(qImgData)>0){
mIosPicker->receiveFile(path); mIosPicker->receiveFile(path);
} }
}else{
qWarning()<<"failed to pick file";
}
[picker dismissViewControllerAnimated:YES completion:NULL]; [picker dismissViewControllerAnimated:YES completion:NULL];
[picker release]; [picker release];
} }
...@@ -83,6 +93,28 @@ void IosGalleryPicker::receiveFile(QString pFileUrl){ ...@@ -83,6 +93,28 @@ void IosGalleryPicker::receiveFile(QString pFileUrl){
void IosGalleryPicker::open() void IosGalleryPicker::open()
{ {
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if(status != PHAuthorizationStatusAuthorized){
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
switch (status) {
case PHAuthorizationStatusAuthorized:
openGalleryPicker();
break;
case PHAuthorizationStatusRestricted:
break;
case PHAuthorizationStatusDenied:
break;
default:
break;
}
}];
}else{
openGalleryPicker();
}
}
void IosGalleryPicker::openGalleryPicker(){
UIViewController *qtController = [[UIApplication sharedApplication].keyWindow rootViewController]; UIViewController *qtController = [[UIApplication sharedApplication].keyWindow rootViewController];
UIImagePickerController *imageController = [[UIImagePickerController alloc] init]; UIImagePickerController *imageController = [[UIImagePickerController alloc] init];
......
...@@ -21,46 +21,24 @@ ...@@ -21,46 +21,24 @@
statusBar.backgroundColor = color; statusBar.backgroundColor = color;
} }
if( SYSTEM_VERSION_LESS_THAN( @"9.0" ) ){
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
{ center.delegate = self;
// for iOS 8 [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; {
[application registerForRemoteNotifications]; if( !error && granted )
}else{
UIUserNotificationType myTypes = UIUserNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;
[application registerForRemoteNotificationTypes:myTypes];
}
}else if( SYSTEM_VERSION_LESS_THAN( @"10.0" ) )
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
if( launchOptions != nil )
{
NSLog( @"registerForPushWithOptions:" );
}
}
else
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
{ {
if( !error ) [[UIApplication sharedApplication] registerForRemoteNotifications]; // required to get the app to do anything at all about push notifications
{ NSLog( @"Push registration success." );
[[UIApplication sharedApplication] registerForRemoteNotifications]; // required to get the app to do anything at all about push notifications }
NSLog( @"Push registration success." ); else
} {
else NSLog( @"Push registration FAILED" );
{ NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription );
NSLog( @"Push registration FAILED" ); NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription ); }
NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion ); }];
}
}];
}
volatile NSDictionary *remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; volatile NSDictionary *remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment