Getting an error when using new UnityCallBack()

+1 vote
http://codeshare.io/3SJ2v

on line 55 I'm getting the error

"Assets/UsersLogin.cs(55,74): error CS0246: The type or namespace name `UnityCallBack' could not be found. Are you missing a using directive or an assembly reference?" Then I'm also getting the errors

Assets/UsersLogin.cs(55,37): error CS1502: The best overloaded method match for `com.shephertz.app42.paas.sdk.csharp.user.UserService.Authenticate(string, string, com.shephertz.app42.paas.sdk.csharp.App42CallBack)' has some invalid arguments

and

Assets/UsersLogin.cs(55,37): error CS1502: The best overloaded method match for `com.shephertz.app42.paas.sdk.csharp.user.UserService.Authenticate(string, string, com.shephertz.app42.paas.sdk.csharp.App42CallBack)' has some invalid arguments

 

I'm following how it is in the tutorial so I'm not sure why this isn't working. Also am I using the onSuccess() function correctly?
asked Mar 6, 2014 in App42 Cloud API-BaaS by JoeCrill (25 points)

1 Answer

0 votes

You are getting this exception because, UnityCallback is not defined anywhere in your project, UnityCallback is a class, you can make your own class with "XYZ" name, this doesn't matters.

Just Follow these steps :-

1. Make a new class and name it whatever you want, lets say "UnityCallback".

2. Inherit this class from App42CallBack.  Like :-

public class UnityCallback : App42CallBack
{
        
}
 
3. Now you are getting an error ,
"UnityCallback  does not implement interface member `com.shephertz.app42.paas.sdk.csharp.App42CallBack.OnSuccess(object)"
 
"UnityCallback does not implement interface member com.shephertz.app42.paas.sdk.csharp.App42CallBack.OnException(System.Exception)".
 
4. So, implement the unImplemented members, Like this:-
 
public class UnityCallback : App42CallBack
{
 
public void OnSuccess (object response)
{
Debug.Log("Json Response Is :: " + response);
}
 
public void OnException (Exception ex)
{
Debug.Log("Exception Is :: " + ex);
}
        
}
 
5. Now you can call the method "userService.Authenticate(userName, password, new UnityCallback());", from your UsersLogin class, and  you'll get the response OR exception in OnSuccess() and OnException() methods of UnityCallback class.
 
Like this :-
 
public class UnityCallback : App42CallBack
{
 
public void OnSuccess (object response)
{
Debug.Log("Json Response Is :: " + response);
if (response is User)
                {
                    User userObj = (User)response ; // casting the json response to User Object.
                    Debug.Log ("UserName : " + userObj.GetUserName());
                    PlayerPrefs.SetString("userName", userObj.GetUserName());
                    Debug.Log ("EmailId : " + userObj.GetEmail())
                }
}
 
public void OnException (Exception ex)
{
App42Exception exception = (App42Exception)ex;
Debug.Log("Exception Is :: " + exception );
}
        
}
 
You can check response classes(e.g UserResponse, StorageResponse, BuddyResponse etc) in SDK sample.
They all are behaving like UnityCallback.
 
 
 
 
 
 

 

answered Mar 7, 2014 by Akshay.Mishra (179 points)
edited Mar 7, 2014 by Akshay.Mishra
Alright so would I need to create a separate callback for the login, registration, send buddy request, ect since the exceptions are all different and I want different things to have on success?

or is that what this part of the code does?
if (response is User)
                {
                    User userObj = (User)response ; // casting the json response to User Object.
                    Debug.Log ("UserName : " + userObj.GetUserName());
                    PlayerPrefs.SetString("userName", userObj.GetUserName());
                    Debug.Log ("EmailId : " + userObj.GetEmail())
                }
}

And then if that's the case would I just use different if statements for lets say sending a buddy request? something like if (response is BuddyRequest){code} Would this documentation be in the tutorials?
Yes this code is related to use different services in single callback.If you want to use same callback for user service and buddy service  your code look like this:
if (response is User)
{
 // your code
}
else if(response is Buddy)
{
// your code
}

For detail information about our buddy service please visit :
http://api.shephertz.com/app42-docs/buddy-management-service/?sdk=unity#send_friend_request
Would using a single call back for all of my app42 services be efficient? Or is it better practice to use separate for each service?
It's totally depend on your use case but for me i suggest you to use different callback  for each service.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...