[Interest] Qt iOS / App Groups / NSUserDefaults initWithSuiteName / Not persisting (Nuno Santos)
Nuno Santos
nunosantos at imaginando.pt
Fri Nov 16 18:30:53 CET 2018
Colin,
After your suggestion I decided to carefully review all the code… guess what… it was a typo!
Thanks for insisting! I feel stupid! :D
Have a great weekend!
Best regards,
Nuno
> On 15 Nov 2018, at 19:12, Nuno Santos <nunosantos at imaginando.pt> wrote:
>
> Yes, I can! The problem is when I close the app and start it again. The result is null.
>
> Data is not being persisted and I do t understand why... :(
>
> --
> Nuno Santos
>
> No dia 15/11/2018, às 19:07, jlk <jlk2144 at gmail.com <mailto:jlk2144 at gmail.com>> escreveu:
>
>> Hi Nuno,
>>
>> Can you save and restore a simple NSObject, say an NSString?. If so, your problem is probably with converting the QVariant to NSObject. I have not used Qt with iOS yet so I don't have any deeper help than that, sorry!
>> However, Maybe there are helper functions you need to write first? Could you use a JSON converter to represent your QVariant as an (NS)string for storage?
>> Colin
>>
>> On 11/15/18 1:31 PM, Nuno Santos wrote:
>>> Colin,
>>>
>>> Thanks for your reply.
>>>
>>> While you are right considering the code I have posted here, the truth is that in my actual code I have the setObject. But since I have more stuff going on I didn’t want to flood the list with code:
>>>
>>> void Settings::setSharedKey(QString key, QVariant value)
>>> {
>>> if (defaults==nil)
>>> defaults = [[NSUserDefaults alloc] initWithSuiteName:@“group.com.acme.app"];
>>>
>>> [defaults setObject:[ISettingsManagerCocoaHelper variantToNSObject:value] forKey:key.toNSString()];
>>> [defaults synchronize];
>>> }
>>>
>>> I’m still struggling with this. I can’t have the settings saved. I’m tired to googling and trying stuff.
>>>
>>> Any ideas? Do you have anything similar?
>>>
>>> Thanks!
>>>
>>> Regards,
>>>
>>> Nuno
>>>
>>>> On 15 Nov 2018, at 17:17, Colin Worth <jlk2144 at gmail.com <mailto:jlk2144 at gmail.com>> wrote:
>>>>
>>>> Hi Nuno,
>>>> You are missing a line, something like:
>>>>
>>>> [defaults setValue:object forKey:key]
>>>>
>>>> in setSharedKey.
>>>>
>>>>>
>>>>> From: Nuno Santos <nunosantos at imaginando.pt <mailto:nunosantos at imaginando.pt>>
>>>>> Subject: [Interest] Qt iOS / App Groups / NSUserDefaults initWithSuiteName / Not persisting
>>>>> Date: November 14, 2018 at 7:24:06 AM AST
>>>>> To: "interest at qt-project.org <mailto:interest at qt-project.org> Interest" <interest at qt-project.org <mailto:interest at qt-project.org>>
>>>>>
>>>>>
>>>>> Hi,
>>>>>
>>>>> I’m trying to persist data in a App Group on Qt iOS app to share data between a standalone app and app extension.
>>>>>
>>>>> I have been reading on how to do it and apparently is dead simple -> https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW6 <https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW6>
>>>>>
>>>>> The problem is that it is not persisting data….
>>>>>
>>>>> I’m starting to question the model I’m following in terms of code. I have my Settings manager in C++. What I have done was to create a SettingsCocoa.mm file that does what is below.
>>>>>
>>>>> In a app session, the value is persisted but as soon as I start the app again, the value is null.
>>>>>
>>>>> As anyone experienced similar issues before? Any ideas would be highly appreciated.
>>>>>
>>>>> Thanks in advance.
>>>>>
>>>>> Best regards,
>>>>>
>>>>> Nuno
>>>>>
>>>>>
>>>>> #include "Settings.h"
>>>>>
>>>>> #import <Foundation/Foundation.h>
>>>>> #include <QDebug>
>>>>>
>>>>> static NSUserDefaults *defaults = nil;
>>>>>
>>>>> QVariant Settings::sharedKey(QString key, const QVariant &defaultValue) const
>>>>> {
>>>>> if (defaults==nil)
>>>>> defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.acme.app"];
>>>>>
>>>>> NSObject *value = [defaults valueForKey:key.toNSString()];
>>>>> NSLog(@"get object: %@", value);
>>>>> }
>>>>>
>>>>> void Settings::setSharedKey(QString key, QVariant value)
>>>>> {
>>>>> if (defaults==nil)
>>>>> defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.acme.app"];
>>>>>
>>>>> NSObject *object = [ISettingsManagerCocoaHelper variantToNSObject:value];
>>>>> NSLog(@"set object: %@", object);
>>>>>
>>>>> sharedKey(key, value);
>>>>>
>>>>> [defaults synchronize];
>>>>> }
>>>>>
>>>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181116/9810558a/attachment.html>
More information about the Interest
mailing list