尝试仅在iOS 7.1.1上设置非属性列表对象

时间:2014-04-25 04:42:22

标签: ios nsuserdefaults

一切都还可以,但不是 iOS 7.1.1

我不知道为什么。我尝试保存的对象是NSStringNSNumber(我检查了每个对象)

有人帮帮我!

Attempt to set a non-property-list object (
        {
        channel = "No Channel";
        channelId = "";
    },
        {
        backgroundColor = 5082e5;
        channel = Animals;
        channelId = 17;
        created = "2014-02-12T01:16:06.000000";
        exploreIconUrl = "/static/images/channels_v2/Animals_trans@2x.png";
        exploreName = Animals;
        exploreRetinaIconUrl = "/static/images/channels_v2/Animals_trans@2x.png";
        exploreStyle = icon;
        featuredChannelId = 337;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/Animals.png";
        priority = 1;
        retinaIconUrl = "/static/images/channels_v2/Animals@2x.png";
    },
        {
        backgroundColor = be5fb6;
        channel = Art;
        channelId = 2;
        created = "2013-06-28T16:46:54.000000";
        exploreIconUrl = "/static/images/channels_v2/Art_trans@2x.png";
        exploreName = Art;
        exploreRetinaIconUrl = "/static/images/channels_v2/Art_trans@2x.png";
        exploreStyle = icon;
        featuredChannelId = 2;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/Art.png";
        priority = 2;
        retinaIconUrl = "/static/images/channels_v2/Art@2x.png";
    },
        {
        backgroundColor = ff5867;
        channel = Comedy;
        channelId = 1;
        created = "2013-06-28T16:46:54.000000";
        exploreIconUrl = "/static/images/channels_v2/Comedy_trans@2x.png";
        exploreName = Comedy;
        exploreRetinaIconUrl = "/static/images/channels_v2/Comedy_trans@2x.png";
        exploreStyle = icon;
        featuredChannelId = 1;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/Comedy.png";
        priority = 3;
        retinaIconUrl = "/static/images/channels_v2/Comedy@2x.png";
    },
        {
        backgroundColor = 33ccbe;
        channel = DIY;
        channelId = 1070175184667013120;
        created = "2014-04-21T23:44:20.000000";
        exploreIconUrl = "/static/images/channels_v2/DIY_trans@2x.png";
        exploreName = DIY;
        exploreRetinaIconUrl = "/static/images/channels_v2/DIY_trans@2x.png";
        exploreStyle = "<null>";
        featuredChannelId = 1070189388014780416;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/DIY.png";
        priority = 6;
        retinaIconUrl = "/static/images/channels_v2/DIY@2x.png";
    },
        {
        backgroundColor = 68bf60;
        channel = Family;
        channelId = 7;
        created = "2013-06-28T16:46:54.000000";
        exploreIconUrl = "/static/images/channels_v2/Family_trans@2x.png";
        exploreName = Family;
        exploreRetinaIconUrl = "/static/images/channels_v2/Family_trans@2x.png";
        exploreStyle = icon;
        featuredChannelId = 7;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/Family.png";
        priority = 7;
        retinaIconUrl = "/static/images/channels_v2/Family@2x.png";
    },
        {
        backgroundColor = ff794d;
        channel = Food;
        channelId = 10;
        created = "2013-06-28T16:46:54.000000";
        exploreIconUrl = "/static/images/channels_v2/Food_trans@2x.png";
        exploreName = Food;
        exploreRetinaIconUrl = "/static/images/channels_v2/Food_trans@2x.png";
        exploreStyle = icon;
        featuredChannelId = 10;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/Food.png";
        priority = 9;
        retinaIconUrl = "/static/images/channels_v2/Food@2x.png";
    },
        {
        backgroundColor = 6caff1;
        channel = "Music & Dance";
        channelId = 11;
        created = "2013-06-28T16:46:54.000000";
        exploreIconUrl = "/static/images/channels_v2/Music_trans@2x.png";
        exploreName = "Music & Dance";
        exploreRetinaIconUrl = "/static/images/channels_v2/Music_trans@2x.png";
        exploreStyle = icon;
        featuredChannelId = 11;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/Music.png";
        priority = 10;
        retinaIconUrl = "/static/images/channels_v2/Music@2x.png";
    },
        {
        backgroundColor = cccc52;
        channel = News;
        channelId = 14;
        created = "2013-06-28T16:46:54.000000";
        exploreIconUrl = "/static/images/channels_v2/News_trans@2x.png";
        exploreName = News;
        exploreRetinaIconUrl = "/static/images/channels_v2/News_trans@2x.png";
        exploreStyle = icon;
        featuredChannelId = 14;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/News.png";
        priority = 11;
        retinaIconUrl = "/static/images/channels_v2/News@2x.png";
    },
        {
        backgroundColor = 7870cc;
        channel = Places;
        channelId = 5;
        created = "2013-06-28T16:46:54.000000";
        exploreIconUrl = "/static/images/channels_v2/Places_trans@2x.png";
        exploreName = Places;
        exploreRetinaIconUrl = "/static/images/channels_v2/Places_trans@2x.png";
        exploreStyle = icon;
        featuredChannelId = 5;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/Places.png";
        priority = 14;
        retinaIconUrl = "/static/images/channels_v2/Places@2x.png";
    },
        {
        backgroundColor = f279ac;
        channel = "Science & Tech";
        channelId = 1070175340166619136;
        created = "2014-04-21T23:44:57.000000";
        exploreIconUrl = "/static/images/channels_v2/Science_trans@2x.png";
        exploreName = "Science & Tech";
        exploreRetinaIconUrl = "/static/images/channels_v2/Science_trans@2x.png";
        exploreStyle = "<null>";
        featuredChannelId = 1070188045032366080;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/Science.png";
        priority = 15;
        retinaIconUrl = "/static/images/channels_v2/Science@2x.png";
    },
        {
        backgroundColor = 548899;
        channel = Sports;
        channelId = 9;
        created = "2013-06-28T16:46:54.000000";
        exploreIconUrl = "/static/images/channels_v2/Sports_trans@2x.png";
        exploreName = Sports;
        exploreRetinaIconUrl = "/static/images/channels_v2/Sports_trans@2x.png";
        exploreStyle = icon;
        featuredChannelId = 9;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/Sports.png";
        priority = 16;
        retinaIconUrl = "/static/images/channels_v2/Sports@2x.png";
    },
        {
        backgroundColor = ffaf40;
        channel = Style;
        channelId = 12;
        created = "2013-06-28T16:46:54.000000";
        exploreIconUrl = "/static/images/channels_v2/Fashion_trans@2x.png";
        exploreName = Style;
        exploreRetinaIconUrl = "/static/images/channels_v2/Fashion_trans@2x.png";
        exploreStyle = icon;
        featuredChannelId = 12;
        fontColor = ffffff;
        iconUrl = "/static/images/channels_v2/Fashion.png";
        priority = 17;
        retinaIconUrl = "/static/images/channels_v2/Fashion@2x.png";
    }
) as an NSUserDefaults value for key kChannelList

=========================================

完成

好的,我找到了导致此错误的原因。在我尝试保存到NSUserDefault的对象中,有一些 NSNull 对象。 (您可以在我的帖子中使用关键字“NSNull”进行搜索)

在iOS 7.1.1下,iOS只显示了一条警告消息,但在iOS 7.1.1上, APP将崩溃

删除所有具有NSNull值的键。我正在使用AFNetworking,所以我写道:

+ (AFJSONResponseSerializer *)afJsonResponseserializer {
    AFJSONResponseSerializer *ret = [AFJSONResponseSerializer serializer];
    ret.removesKeysWithNullValues = YES;
    return ret;
}

并在我需要的任何地方使用它来解析JSon

1 个答案:

答案 0 :(得分:0)

尝试仅添加此代码的一部分。您应该能够将其缩小到给出错误的行。

考虑到这一点,请记住,属性列表仅包含某些类型的数据:字典,数组,字符串,数字(整数和浮点数),日期,二进制数据和布尔值。例如,如果您的icon是UIImage,则不允许将其添加到plist中。