Dridia
Dridia

Reputation: 183

Sending username as a variable in a parse push-notification

How can i add the current users username in a parse.com push-notification message?

This is the code i have:

pushQuery = [PFInstallation query];
[pushQuery whereKey:@"userStable" equalTo:SecondStable];

pushNotify = [[PFPush alloc] init];
[pushNotify setQuery:pushQuery];
NSString *username = currentUser[@"username"];
[pushNotify setMessage:@"%@ sent you a message", username];
[pushNotify sendPushInBackground];

I have pushQuery and pushNotify as properties in my .h file.

I get an error message saying:

Too many arguments to method call, expected 1, have 2.

Upvotes: 0

Views: 132

Answers (1)

Lyndsey Scott
Lyndsey Scott

Reputation: 37290

You're attempting to format your message string incorrectly.

[pushNotify setMessage:@"%@ sent you a message", username];

should be:

[pushNotify setMessage:[NSString stringWithFormat:@"%@ sent you a message", username]];

As your code stands now, I believe the error is mistaking "username" for a second argument in setMessage, thus the error message: "Too many arguments to method call, expected 1, have 2."

Upvotes: 1

Related Questions