How can i run some code then i got "Push notification"? in Objective c.
Then my app is running i got push notification, but then my app is closed i got nothing. but not push notification in Suspended), but can't run some code
Here is my code.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {}
But nothing happen!
All what i want is run some code in background fetch in (Suspended)!
Related
In the fabric crash logs I can see some records from functions which calls from background:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
The Fabric docs says that logs will be retrieved when user manually relaunched the app but before this the app can be relaunched automatically by the Background Execution and related functions can add more logs after crash. Is it correct?
I am facing a problem with Push notification, and the problem occurs only on clients Enterprise environment.
The problem is as follows: when I am testing on my side (development and not distribution) I receive notification and - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo is called every time and works perfectly through the following cases:
When app is not opened (not in memory or suspended apps), and not in background nor foreground
When app is opened but in background.
When app is in foreground.
But when the client tries it on his environment (after mdm wrapping), the following happens in each case:
Case 1: Works successfully, and didReceiveRemoteNotification method gets called fine.
Case 2: Receives notification, but didReceiveRemoteNotification is not called.
Case 3: I don't see any notification neither in notification centre and didReceiveRemoteNotification is not called also.
I searched for anything that could help, and I only found that there is this - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler maybe be a better replacement.
Any other suggestions? Any thing to check or to consider? Is it maybe an iOS related issue? Caused by MDM configuration (a long shot I know)?.
Thanks in advance.
I found the solution, I used this method - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler which suited well.
In an iOS app using remote notifications (coming from Parse.com) I have arrived, after spending some time researching on the subject, to the conclusion that I should not use remote notifications in the background or possibly use silent notifications.
But silent notification seem quite complex.
For example:
In this code:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSLog(#"application:didReceiveRemoteNotification:fetchCompletionHandler:");
completionHandler(UIBackgroundFetchResultNewData);
}
The fact of adding the last line (completionHandler) prevents an error message.
But what does this do exactly? Where does this completionHandler come from?
I have never touched silent-notifications and I am kind of lost there.
The last line is completing block that will be called when you application is in background.
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
Above method get called when your application in running in background OR foreground mode.
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
If you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives.
When a remote notification arrives, the system displays the notification to the user and launches the app in the background (if needed) so that it can call this method. Launching your app in the background gives you time to process the notification and download any data associated with it, minimizing the amount of time that elapses between the arrival of the notification and displaying that data to the user.
Let me know if you need anymore clarification.
Although this was asked in several places I haven't seen one answer that helped me.
I am trying to get a push notification and tried the following functions:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
The issue:
I am only able to receive the remote notification if the app is in foreground. If it's in background, nothing gets invoked.
I am using iOS8.
The following background modes are checked: "Background fetch","Remote notification"
Can anyone help me with that?
Its pretty deep in the documenation, but in your JSON payload, you need to set the 'content-available' to 1.
https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
If your payload doesn't have an "alert" or "content-available" then you won't get a notification in your app delegate.
I am using iOS7 and I am trying to determine if I can get the JSON payload in the following situation.
I have background mode "remote-notifications" enabled
The push notification is received while the app is terminated
The app is launched manually from the icon not from the notification center
When I launch the app from the icon itself after the notification has been received I do not get the push in the launch options from
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
and the following method does not get called either when app is manually launched from the icon
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
I finally figured out how you can get this!
As of iOS 7 you can get it!
Basically, you need to configure your application for background remote notifications.
So, in your info.plist file:
For required backgrounds - set it to app downloads content from push notifications.
In the AppDelegate.m file, you need to implement this method:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
See this for how to implement that: didReceiveRemoteNotification: fetchCompletionHandler: open from icon vs push notification
For your push notifications, you must have 'content-available': 1, as part of the push notification. This is what tells the application that there is new content before displaying the alert.
See this page for more information on background remote notifications: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/backgrounding/part_3_ios_backgrounding_techniques/updating_an_application_in_the_background/