Save (Private) Application Settings on iOS?

前端 未结 3 891
情书的邮戳
情书的邮戳 2021-02-01 17:01

I\'m aware of NSUserDefaults for saving/restoring user preferences. What is the equivalent class for an application

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-01 17:38

    if you can store value by NSUserDefaults, then it is good to store application preferences too.

    or add settings.plist on your project and read that (what you are not changing later)

    and you can use like.,

    + (NSDictionary*)getBundlePlist:(NSString *)plistName
    {
        NSString *errorDesc = nil;
        NSPropertyListFormat format;
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];
        NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
        NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                              propertyListFromData:plistXML
                                              mutabilityOption:NSPropertyListMutableContainersAndLeaves           
                                              format:&format errorDescription:&errorDesc];
        return temp;
    }
    
    + (id) getPropValue:(NSString *)PropertyName
    {   // I am supposing you had add your app preferences on settings.plist.
        return [[Property getBundlePlist:@"settings"] objectForKey:PropertyName];
        //here Property is my class name, then you can use value by 
        //NSString *value = [Property getPropValue:@"setting1"];
    }
    

提交回复
热议问题