#import #import #import #include #include "platformintegration/ios/platformhelperios.h" QString PlatformHelperIOS::readKeyChainEntry(const QString &service, const QString &key) { NSDictionary *const query = @{ (__bridge id) kSecClass: (__bridge id) kSecClassGenericPassword, (__bridge id) kSecAttrService: (__bridge NSString *) service.toCFString(), (__bridge id) kSecAttrAccount: (__bridge NSString *) key.toCFString(), (__bridge id) kSecReturnData: @YES, }; CFTypeRef dataRef = nil; const OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef) query, &dataRef); QByteArray data; if (status == errSecSuccess) { if (dataRef) data = QByteArray::fromCFData((CFDataRef) dataRef); } else { qWarning() << "Error accessing keychain value" << status; } if (dataRef) [dataRef release]; return data; } void PlatformHelperIOS::writeKeyChainEntry(const QString &service, const QString &key, const QString &value) { NSDictionary *const query = @{ (__bridge id) kSecClass: (__bridge id) kSecClassGenericPassword, (__bridge id) kSecAttrService: (__bridge NSString *) service.toCFString(), (__bridge id) kSecAttrAccount: (__bridge NSString *) key.toCFString(), }; OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef) query, nil); if (status == errSecSuccess) { NSDictionary *const update = @{ (__bridge id) kSecValueData: (__bridge NSData *) value.toUtf8().toCFData(), }; status = SecItemUpdate((__bridge CFDictionaryRef) query, (__bridge CFDictionaryRef) update); } else { NSDictionary *const insert = @{ (__bridge id) kSecClass: (__bridge id) kSecClassGenericPassword, (__bridge id) kSecAttrService: (__bridge NSString *) service.toCFString(), (__bridge id) kSecAttrAccount: (__bridge NSString *) key.toCFString(), (__bridge id) kSecValueData: (__bridge NSData *) value.toUtf8().toCFData(), }; status = SecItemAdd((__bridge CFDictionaryRef) insert, nil); } if (status == errSecSuccess) { qDebug() << "Successfully stored value in keychain"; } else { qWarning() << "Error storing value in keycahin" << status; } } void PlatformHelperIOS::generateSelectionFeedback() { UISelectionFeedbackGenerator *generator = [[UISelectionFeedbackGenerator alloc] init]; [generator prepare]; [generator selectionChanged]; generator = nil; } void PlatformHelperIOS::generateImpactFeedback() { // UIImpactFeedbackStyleLight // UIImpactFeedbackStyleMedium // UIImpactFeedbackStyleHeavy UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight]; [generator prepare]; [generator impactOccurred]; generator = nil; } void PlatformHelperIOS::generateNotificationFeedback() { // UINotificationFeedbackTypeSuccess // UINotificationFeedbackTypeWarning // UINotificationFeedbackTypeError UINotificationFeedbackGenerator *generator = [[UINotificationFeedbackGenerator alloc] init]; [generator prepare]; [generator notificationOccurred:UINotificationFeedbackTypeSuccess]; generator = nil; } void PlatformHelperIOS::setTopPanelColorInternal(const QColor &color) { UIView *statusBar = (UIView *)[[UIApplication sharedApplication] valueForKey:@"statusBar"]; statusBar.backgroundColor = [UIColor colorWithRed:color.redF() green:color.greenF() blue:color.blueF() alpha:color.alphaF()]; if (((color.red() * 299 + color.green() * 587 + color.blue() * 114) / 1000) > 123) { [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES]; } else { [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES]; } } void PlatformHelperIOS::setBottomPanelColorInternal(const QColor &color) { //Bottom UIApplication *app = [UIApplication sharedApplication]; app.windows.firstObject.backgroundColor = [UIColor colorWithRed:color.redF() green:color.greenF() blue:color.blueF() alpha:color.alphaF()]; }