Shopify / mobile-buy-sdk-ios

Shopify’s Mobile Buy SDK makes it simple to sell physical products inside your mobile app. With a few lines of code, you can connect your app with the Shopify platform and let your users buy your products using Apple Pay or their credit card.
MIT License
452 stars 199 forks source link

getProducts and getCollections, parsing product, collection error, NSArrayM insertObject:atIndex:]: object cannot be nil' #561

Closed webmaster100 closed 7 years ago

webmaster100 commented 7 years ago

Hi, I want to use the mobile-buy-sdk-ios with react-native-shopify. When calling methods getProducts(1) and getCollections(1) the products and collections are returned from the requests, but some parsing error occurs after that. The error seems to occur after this line: nsarray buyadditions m edited 2017-04-03 18-25-41 error_nil_object Can you advise what causes this error and how can I resolve it? Thank you!

bgulanowski commented 7 years ago

This usually happens because your app was unable to create the managed object model. Probably because it couldn't find the managed object model file, Mobile Buy SDK.xcdatamodeld, in the bundle. Possibly because you didn't include the SDK resources bundle in your target.

In the code you show there, the problem is that block(obj) is returning nil. If you step into that block (defined in +[BUYModelManager buy_objectsWithEntityName:JSONArray:], you'd see that the cls variable is probably nil, so object instantiation fails. cls is nil because the model manager's model property is nil. Basically, you have a cascade of nil values.

You will have to trace it back to be sure, however.

webmaster100 commented 7 years ago

I have installed the mobile-buy-sdk-ios using Cocoapods and as I see it automatically connects the resources. It is the only place where I found it in the workspace in Xcode image The cls variable have the value: buymodelmanager m edited 2017-04-04 10-07-46 Can be there some product parsing error? It is one of the product in the response: <__NSArrayI 0x6000003a4600>( { available = 1; "body_html" = "

\n

Condition: Barely Used

\n

Personal Note:

\n<p style=\"padding-left: 30px;\">\"not specified\"

\n
"; "created_at" = "2017-04-03T07:47:12-06:00"; handle = "02-04-phone-1"; images = ( { "created_at" = "2017-04-03T04:04:18-06:00"; id = 17319786827; position = 1; "product_id" = 8447042955; src = "https://cdn.shopify.com/s/files/1/1626/9455/products/122a5b147-466c-4e33-8678-49ca87569e5b.jpg?v=1491213858"; "updated_at" = "2017-04-03T04:04:18-06:00"; "variant_ids" = ( ); } ); options = ( { id = 10121130443; name = Title; position = 1; "product_id" = 8447042955; } ); "product_id" = 8447042955; "product_type" = ""; "published_at" = "2017-04-03T07:47:12-06:00"; tags = "Furniture"; title = "02.04 phone"; "updated_at" = "2017-04-03T07:47:12-06:00"; variants = ( { available = 1; barcode = ""; "compare_at_price" = "19.00"; "created_at" = "2017-04-03T04:04:08-06:00"; "formatted_price" = "$9.00"; grams = 0; id = 29192253131; "option_values" = ( { name = Title; "option_id" = 10121130443; value = "Default Title"; } ); position = 1; price = "9.00"; "requires_shipping" = 1; sku = ""; taxable = 0; title = "Default Title"; "updated_at" = "2017-04-03T07:47:12-06:00"; } ); vendor = Name; },

bgulanowski commented 7 years ago

Your screenshot clearly shows cls == 0x0, in other words, Nil (I incorrectly said nil before). cls should be a class object. Without that, [cls alloc] is nil. So there's no reason that I can see to suspect a parsing error.

If there was a parsing error, it would be in Apple's JSON deserialization, but in that case, you would have seen an error logged to the console and nil returned instead of a dictionary. You should be able to easily verify that. In terms of mapping the dictionary contents to a new object, even if that failed for some reason, you would still get a new object returned, but it's properties would not have the right values.

webmaster100 commented 7 years ago

The error was fixed when I copied by reference the datamodel file to Compile Sources as mentioned in this thread image Thank you!

RB-King commented 7 years ago

@webmaster100 Hello Sir, You have idea in WebCheckout and Shipping rates ?

webmaster100 commented 7 years ago

@JaydeepPatel, Hello, I used react-native-shopify package for webcheckout and getting shipping rates.