This is how we handle them at XCode:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSString *message = nil;
id alert = [userInfo objectForKey:#"alert"];
if ([alert isKindOfClass:[NSString class]]) {
message = alert;
} else if ([alert isKindOfClass:[NSDictionary class]]) {
message = [alert objectForKey:#"body"];
}
if (alert) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Title"
message:#"AThe message." delegate:self
cancelButtonTitle:#"button 1"
otherButtonTitles:#"button", nil];
[alertView show];
[alertView release];
}
How do we catch Push Notifications if the iOS application is already running at the same way but using Delphi 10 Seattle?
Note: Sadly I can not test this as I don't have a Mac with me at the moment but this should work
Inside FMX.Platform.iOS you will find the
ApplicationDidReceiveRemoteNotification
Method, so it is implemented in Delphi
procedure TApplicationDelegate.applicationDidReceiveRemoteNotification(
Sender: UIApplication; ANotification: NSDictionary);
begin
PlatformCocoa.ReceivedRemoteNotification(ANotification);
end;
In there you can then get the Notification as a NSDictionary and you can then read the values from that NSDictionary to handle it in a way that you want
You can also refer to Remy's answer on my one question regarding method swizzling telling the App to rather use your version of ApplicationDidReceiveRemoteNotification and not the one in the source
iOS only
Drop a TEMSProvider component on the form
Drop a TPushEvents component on the form
Bind the TPushEvents.Provider to the TEMSProvider
in code somewhere set TPushEvents.Active := True or enable it's AutoActivate property
TPushEvents has an event called PushEvents1PushReceived handle it
Related
I am using Sinch SDK version is: 3.7.1-0313526 - with Xcode 6.3 - IOS SDK 8.3 and I would like to know what is the best way to let the app know that there was a missed call when it was in background or not running so I can update UI and badges for missed calls.
The behaviour which I am looking for it's pretty standard. The app is in background or not running, a call arrives. If it is a missed call, the app badge will be update and the notification shown will change to 'Missed call'. Like all the other calling apps.
So far I have tried the following to try to get the missed call from sinch:
- (void)handleRemoteNotification:(NSDictionary *)userInfo {
// Extract the Sinch-specific payload from the Apple Remote Push Notification
NSString* SIN = [userInfo valueForKey:#"sin"];
// Get previously initiated Sinch client
id<SINClient> client = _client;
id<SINNotificationResult> result = [client relayRemotePushNotificationPayload: SIN];
if ([result isCall] && [[result callResult] isTimedOut]) {
//Let set the badge number
[self setTheCallBadgeValue];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Missed call"
message:[NSString stringWithFormat:#"Missed call from %#", callerName]
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil];
[alert show];
}
}
I call the above method from:
#pragma mark - SINManagedPushDelegate
- (void)managedPush:(id<SINManagedPush>)unused
didReceiveIncomingPushWithPayload:(NSDictionary *)payload
forType:(NSString *)pushType {
// NSLog(#"Incoming push - This is the payload: %#", payload);
[self handleRemoteNotification:payload];
}
Unfortunately, that only seems to work on the following cases:
User needs to tap on the notification alert after a few second (around 10s)
The app will open, then it will show the alert for missed call
If user doesn't tap on the notification alert after waiting a few seconds or just ignore the notification alert and just open the app by tapping on the app icon, the app will never know that there was a missed call as "[[result callResult] isTimeout] will not become true", therefore the app will never update UI and the user won't never know that there was a missed call.
For full disclosure, I am using Parse SDK version is 1.7.4 and only added Push notification as a mean to inform the client of new calls:
#pragma Mark - Let Instantiate Sinch!
- (void)initSinchClientWithUserId:(NSString *)userId {
// NSLog(#"Sinch client has started with user id: %#", userId);
if (!_client) {
_client = [Sinch clientWithApplicationKey: SINCH_APPLICATION_KEY
applicationSecret: SINCH_APPLICATION_SECRET
environmentHost: SINCH_ENVIRONMENT_HOST
userId:userId];
_client.delegate = self;
_client.callClient.delegate = self;
[_client setSupportCalling:YES];
[_client enableManagedPushNotifications];
[_client setSupportActiveConnectionInBackground:NO];
[_client start];
// [_client startListeningOnActiveConnection];
NSString *currUsrName = [userDefaults objectForKey:#"currentUserFullName"];
[_client setPushNotificationDisplayName:currUsrName];
}
}
Thank you very much in advance for any help.
You could send a push via parse when you recieve calldid end with reason noanswer.
I have written a function to login to a web service using objective c
- (void) registerAck: (NSNotification *) notification {
NSLog(#"Detected callback for register");
NSString *status = [[notification userInfo] valueForKey:#"result"];
if([status rangeOfString:#"Successful"].location != NSNotFound){
//succesfully registered
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Welcome"
message:#"Thank you for registering. Please login using the created details"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[[NSNotificationCenter defaultCenter] removeObserver:self];
NSLog(#"%#", status);
}
I want to know how I would go about clearing the page and then when the user selects ok on my popup chaining the page to a different one?
The clear page is easy, I would just write a method and then call this before alert[show] but the change of page is where I am stuck - can anyone let me know how I could redirect to a login page programatically?
i m trying to customize notification view, like when we receive default notification its displaying 'DOT' symbol, but i want below image format, here i attached whatever i required notification in my app. pls help me any body knows,
under didReceiveRemote Notification i wrote, like below
mv1 = [[mv alloc]init];
NSLog(#"test%#",userInfo);
[mv1 displayItem:userInfo]; // custom method
imgview.image=[UIImage imageNamed:#"img1.jpeg"];
// NSMutableDictionary *test = [userInfo objectForKey:#"aps"];
// UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Message" message:[test objectForKey:#"alert"] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
// [alert show];
//[[NSNotificationCenter defaultCenter] postNotificationName:#"pushNotification" object:nil userInfo:userInfo];
You cant customize notification centre. Because it is related with the OS not a part of your app. Apple wont allow this customization .
I've searched other questions similar to this here and I can't find any that seem to actually work. What I'm trying to do is when the user opens the app from a local notification, I need it to execute some code (such as opening the UIMessageComposer or displaying a UIAlertView). Anyone have any idea on how I would do this? Just as a note it is a local notification not a push notification.
You need to implement this method in you AppDelegate.m file
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
You can do want you want in this.
Here's a good tutorial on how to work with Local notifications. http://www.appcoda.com/ios-programming-local-notification-tutorial/
use this
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Reminder"
message:notification.alertBody
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
// Set icon badge number to zero
application.applicationIconBadgeNumber = 0;
}
I have successfully used APNS in iphone app and still have a problem the alert customization.Below is my question:
1 I can't custom the Alert view,like title and button title.I custom the alert like:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSDictionary *apsDic = [userInfo valueForKey:#"aps"];
NSString *alertStr = [apsDic valueForKey:#"alert"];
NSNumber *badgeNum = [apsDic valueForKey:#"badge"];
NSString *soundStr = [apsDic valueForKey:#"sound"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[arr objectAtIndex:1]
message:msg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"view",nil];
[alert show];
[alert release];
}
In my App, the title of the alert is my app's title;and the button titles are "Close" and "View".
2 when I click the "View", is shows the launch view of my app and then it crashes.Why?
So if the alert is provided by the system which can't be customized, the view action is also under control of system. It seems there's contradiction between 1 and 2.
Any help is appreciated!
thanks
I find: if your app does not start, the apns-alert is provided by the iOS which you can't customize.