(void)didReceiveLocationPushPayload:(NSDictionary <NSString *, id> *)payload completion:(void (^)(void))completion unable to trigger
I have successfully applied for the com.apple.developer.location.push authority and followed the documentation and implemented everything, the notifications are successfully sent from the server with all the required headers, but the client didReceiveLocationPushPayload method did not respond.
Related
I am using QuickBlox (2.6.3) in my app to implement video chat.Incoming call function is successfully working but whenever i try to make a call (i.e outgoing call) to a specific user,the following method is called
- (void)session:(QBRTCSession *)session rejectedByUser:(NSNumber *)userID userInfo:(NSDictionary *)userInfo {
where as the receiver receives the call and before it accept the call the above method is called while receiver is unaware of rejection,and call is not ended on receiver side.Receiver is portal.
I set following parameters but i am not getting any success
[QBRTCConfig setAnswerTimeInterval:45];
[QBRTCConfig setDisconnectTimeInterval:30];
[QBRTCConfig setDialingTimeInterval:10];
[QBSettings setAutoReconnectEnabled:true];
[QBSettings setReconnectTimerInterval:3];
Please help me what i am missing.Thanks.
I would like to know if I can create a service to send customized user-specific push notifications for iOS.
Example
#"Hey %#, how you doin", firstName"
Is this possible?
Unless I completely misunderstood what you need, no answer has what you need.
Here's a relevant example from the APNS guide :
let’s consider an example. The provider specifies the following dictionary as the value of the alert property:
{ "aps" :
{
"alert" : {
"loc-key" : "GAME_PLAY_REQUEST_FORMAT",
"loc-args" : [ "Jenna", "Frank"]
}
}
}
When the device receives the notification, it uses "GAME_PLAY_REQUEST_FORMAT" as a key to look up the associated string value in the Localizable.strings file in the .lproj directory for the current language. Assuming the current localization has an Localizable.strings entry such as this:
"GAME_PLAY_REQUEST_FORMAT" = "%# and %# have invited you to play Monopoly";
the device displays an alert with the message “Jenna and Frank have invited you to play Monopoly”.
Of course. Check out the APNS programming guide, specifically the payload, which you can customize on your server before you send it to the user's device.
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
Also note that if you know when the notification should appear (not at a dynamic time) then look into local notifications, which don't require a server backend.
You can use any service for Push Notification (as listed) or do it by yourself.
In your code, when you receive the Push Notification message:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(#"Received notification: %#", userInfo);
//here you should treat your received data
}
There are some very good solutions for iOS push notifications service that use APNS. No need to implement it on your own.
PushApps - free for 1M notifications per month, and unlimited notifications for 19.99 per month, and you can import your users via the API or by sending the a csv file - documentation
Urban Airship - free up to 1M notifications per month, afterwards you are charged per 1000 notifications
Parse - also free for the first 1M notifications
PushWoosh - free for 1M devices, premium plans are from 39 EURO
If you have to implement it on your own, have a look at easyAPNS if you want to host it yourself.
Another good site for info is Ray Wenderlich's site which hosts a 2 part tutorial:
Apple Push Notification Services Tutorial: Part 1/2
Apple Push Notification Services Tutorial: Part 2/2
Or this, Apple Push Notification module for Node.js.
Of course you can...
You need to create your own back-end php file for push notification service, you can send json data from your app to the php file and use $GET to achieve the data you want, including device token, message, badge number... please refer to this
in your viewController
NSString *finalUrl =[NSString stringWithFormat:#"%#/pushService.php?device_token=%#&passphrase=%#&msg=%#",baseURL,device_token,passphrase,msg];
NSURL *url =[NSURL URLWithString:finalUrl];
NSData *jsonData = [NSData dataWithContentsOfURL:url];
if(jsonData != nil)
{
NSError *error = nil;
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
NSLog(#"result: %#", result);
}else
{
NSLog(#"connection error!");
}
pushService.php file
// Put your device token here (without spaces):
$deviceToken = $GET['device_token'];
// Put your private key's passphrase here
$passphrase = $GET['passphrase'];
// Put your alert message here:
$message = $GET['msg'];
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'badge' => 5
);
I am working on an iOS app with a chat function. I want to know if there is any resource to configure the XMPPFramework in order to connect my iOS app with Openfire server.
I am new to XMPP Protocol.
I am currently learning about XMPP Stream and Rosters but I need to at least get the connection to work.
Please help.
To get yourself started, dive into the sample iOS project in XMPPFramework-master > Xcode > iPhoneXMPP.
Preferably, begin tweaking in the project itself, and get your understanding from there before moving on to create your own XMPP project.
Basically to connect XMPP to OpenFire server, most of the configurations lie in AppDelegate.
Set your OpenFire server's details in the XMPP setup:
- (void)setupStream
{
...
// Specify your server's IP address
[xmppStream setHostName:#"123.12.123.12"];
// Specify your host port
[xmppStream setHostPort:5222];
}
Assuming you have already created a contact in your OpenFire's roster, set a contact's credentials in the XMPP connection method:
- (BOOL)connect
{
/**
* Of course, do not hardcode in an actual implementation
* Appending the server name at the back of user ID is necessary
*/
myJID = #"user#openfire";
myPassword = #"password goes here";
}
Ensure you call the connect method in app launch method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self connect];
}
Ensure you are connected here:
- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
NSLog(#"User Connected");
// You are connected to the server at this point.
}
Ensure you are authenticated here:
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
NSLog(#"User Authenticated");
/**
* Once you've reached this point,
* Check your server for the online users.
* You should now be seen as "available".
* Cheers!
*/
}
All the codes I use are from https://github.com/robbiehanson/XMPPFramework. Inside the sample code.
In my iOS7 messaging app, I invoke the "connect" function inside XMPP Framework after the user has entered their login credential and clicked the "login" button. The connect function works fine if they entered the correct credentials the first time, but would not work if the user entered the wrong credential. Because this very first line inside connect would simply return TRUE:
if (![_xmppStream isDisconnected]) {
return YES;
}
Which means any further presses on the login button would do nothing.
Should I manually invoke authenticateWithPassword? Is this the right practice assuming a connection between the client and the server has been setup?
Thank you.
You need to use the methods in the delegate to handle authentication. First you need to connect to the server if it's not already connected:
[_xmppStream connectWithTimeout:10 error:&error];
Once the stream is connected to the server the delegate method will be invoked:
- (void)xmppStreamDidConnect:(XMPPStream *)sender;
Inside that method, you can call authenticateWithPassword. If the stream was previously connected (would be the else part of the if you posted) you can just call authenticateWithPassword.
If authentication fails, the following delegate method is called:
- (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(NSXMLElement *)error;
There you can decide to show a message to the user and start over. If authentication succeeds, the following method is called:
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender;
I am trying to send a json format which doesn't have an "alert" attribute. The thing is, when I try to remove the alert attribute, the notification won't appear. Is there any way I can handle this? Thanks in advance
P.S I've tried to use action, however it still doesn't show up (I think this is only possible in android)
Yes, you can do it. It is possible to send a push notification without an alert. You can even register your application just to badge notifications, in which case the provider server won't even be able to send alerts or sounds.
The Notification Payload
Each push notification carries with it a payload. The payload specifies how users are to be alerted to the data waiting to be downloaded to the client application. The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit. Remember that delivery of notifications is “best effort” and is not guaranteed.
For each notification, providers must compose a JSON dictionary object that strictly adheres to RFC 4627. This dictionary must contain another dictionary identified by the key aps. The aps dictionary contains one or more properties that specify the following actions:
An alert message to display to the user
A number to badge the application icon with
A sound to play
Note that it says one or more of the properties. The alert property is optional. You can even send a notification with an empty aps dictionary (i.e. send only custom properties).
The following example shows an empty aps dictionary; because the badge property is missing, any current badge number shown on the application icon is removed. The acme2 custom property is an array of two integers.
{
"aps" : {
},
"acme2" : [ 5, 8 ]
}
The only alert the user will see it the alert that asks him/her whether to allow push notifications. That alert will only be displayed the first time the app is launched after installation.
In the below example you register to non alert notifications (badges and sounds only) :
Registering for remote notifications
- (void)applicationDidFinishLaunching:(UIApplication *)app {
// other setup tasks here....
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}
// Delegation methods
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
const void *devTokenBytes = [devToken bytes];
self.registered = YES;
[self sendProviderDeviceToken:devTokenBytes]; // custom method
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(#"Error in registration. Error: %#", err);
}
Hope this will help you.