Override (network.request) creates rejection of apple

I made a override of the network.request method, something like:

local original\_request = network.request function network.request( url, metod, listener, params) params = params or {} if( (params.body=="")or(not params.body) )then params.body = "serverAppKey="..serverAppKey elseif(params.body)then params.body = params.body.."&serverAppKey="..serverAppKey end if((registeredPlayer)and(network.getConnectionStatus().isConnected))then return original\_request(url, metod, listener, params) else listener({isError=true}) return false end end

if I add this method (even without calling it once) the app crashes and closes.

why this? How do I solve?

Hi,

The “original_request” is just a reference to “network.request” so you’re not really overriding it. When you then assign “network.request” as a function the app is most likely going to crash.

If you want to “override” it you should probably wrap it in a module or try using a metatable.

-dev

Hello. Thanks for the quick answer.

I did not think that “original_request”  is a reference.

I use the same method for display.newImageRect and this does not give problems. Why?

at the moment, however, I solved doing something like:

myNetwork = {} function myNetwork.request( url, metod, listener, params) params = params or {} if( (params.body=="")or(not params.body) )then params.body = "serverAppKey="..serverAppKey elseif(params.body)then params.body = params.body.."&serverAppKey="..serverAppKey end if((registeredPlayer)and(network.getConnectionStatus().isConnected))then return network.request(url, metod, listener, params) else listener({isError=true}) return false end end

and changing all my requests from “network.request” to “myNetwork.request”. But I do not really like this solution.

Could you give me a small example to make a real override without creating problems?

Hi,

Yes I am mistaken. Your code works fine. Is this only happening on iOS? I ran it on Android and it worked fine:

local serverAppKey = "1234" local registeredPlayer = true local original\_request = network.request function network.request(url, method, listener, params) params = params or {} if( (params.body == "" ) or (not params.body) )then params.body = "serverAppKey="..serverAppKey elseif( params.body )then params.body = params.body.."&serverAppKey="..serverAppKey end if( ( registeredPlayer ) and ( network.getConnectionStatus().isConnected ) ) then return original\_request(url, method, listener, params) else listener({ isError = true }) return false end end local function onRequest(e) print('requested') print(e.response) end network.request('https://www.coroniumcore.com', "GET", onRequest)

-dev

Yes, I distributed it for android and I had no problma.

Then I distributed on iOS and in a hurry I did not test so the app was rejected.

I then tested the app and after several hours I realized that the problem was that part of the code.

This is the mistake I received:

 Class VCWeakObjectHolder is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/ iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/ RuntimeRoot/System/Library/PrivateFrameworks/AVConference.framework/Frameworks/ViceroyTrace.framework/ ViceroyTrace (0x1286884d0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/ Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/ Library/PrivateFrameworks/AVConference.framework/AVConference (0x128507f48). One of the two will be used. Which one is undefined.

Hi,

The “original_request” is just a reference to “network.request” so you’re not really overriding it. When you then assign “network.request” as a function the app is most likely going to crash.

If you want to “override” it you should probably wrap it in a module or try using a metatable.

-dev

Hello. Thanks for the quick answer.

I did not think that “original_request”  is a reference.

I use the same method for display.newImageRect and this does not give problems. Why?

at the moment, however, I solved doing something like:

myNetwork = {} function myNetwork.request( url, metod, listener, params) params = params or {} if( (params.body=="")or(not params.body) )then params.body = "serverAppKey="..serverAppKey elseif(params.body)then params.body = params.body.."&serverAppKey="..serverAppKey end if((registeredPlayer)and(network.getConnectionStatus().isConnected))then return network.request(url, metod, listener, params) else listener({isError=true}) return false end end

and changing all my requests from “network.request” to “myNetwork.request”. But I do not really like this solution.

Could you give me a small example to make a real override without creating problems?

Hi,

Yes I am mistaken. Your code works fine. Is this only happening on iOS? I ran it on Android and it worked fine:

local serverAppKey = "1234" local registeredPlayer = true local original\_request = network.request function network.request(url, method, listener, params) params = params or {} if( (params.body == "" ) or (not params.body) )then params.body = "serverAppKey="..serverAppKey elseif( params.body )then params.body = params.body.."&serverAppKey="..serverAppKey end if( ( registeredPlayer ) and ( network.getConnectionStatus().isConnected ) ) then return original\_request(url, method, listener, params) else listener({ isError = true }) return false end end local function onRequest(e) print('requested') print(e.response) end network.request('https://www.coroniumcore.com', "GET", onRequest)

-dev

Yes, I distributed it for android and I had no problma.

Then I distributed on iOS and in a hurry I did not test so the app was rejected.

I then tested the app and after several hours I realized that the problem was that part of the code.

This is the mistake I received:

 Class VCWeakObjectHolder is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/ iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/ RuntimeRoot/System/Library/PrivateFrameworks/AVConference.framework/Frameworks/ViceroyTrace.framework/ ViceroyTrace (0x1286884d0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/ Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/ Library/PrivateFrameworks/AVConference.framework/AVConference (0x128507f48). One of the two will be used. Which one is undefined.