I have registered for push and local notifications with two action buttons: action1 and action2. Upon receiving the notification, I can see both and can also take action depending on the action id. However, one of my use cases requires me to hide one or both the action buttons before I schedule local notification. Can I do that at run-time?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
In this method I am registering for notifications with 2 action buttons.
I see that depending on context we can define variable number of action buttons. However, context is predefined and not user defined.
Register user notification with multiple categories as you required like category1 with two actions, category2 with no action, category3 with only one action.
When creation of local notification, Use a defined category as you required.
like this
notificationName.category = #"Category_identifier";
Related
In Mixpanel you can track each action, like:
[mixpanel track:#"Watched Movie" properties:#{#"Movie ID”:#“1234", #"Movie Name”:#”Rocky 3"}];
And you can set user properties, like:
[mixpanel.people set:#{#"Eye Color":#"Blue"}];
When I want to send an email to a subset of users, I can narrow things down by asking for user properties - Eye Color:Green for instance.
But how do I get a subset of users who have performed a certain action - for instance "Watched Movie" with "Movie Name" "Rocky 3"?
As you have probably noticed, notifications can only be sent based on People Profile Properties. To segment people by events/send notifications based on events, you need to pass event data over to People by adding an extra line of code that sets the event as a people property. As of now, People and Engagement are two separate data sets. We're working on tying these data sets together more tightly, but for the moment they are not seamlessly integrated.
In your example, we would need to fire a people.set as the user watched a movie called Rocky 3
An example of this for iOS would be the following:
[mixpanel.people set:#{#"Rocky 3 Viewed":#"True"}];
Please feel free to write into support#mixpanel.com if you have any other questions!
My app has two different features that can each schedule a local notification. They are both reminders, but for different things, and for different parts of the app. Is there a way to schedule 2 different actions for these? For example, clicking notification style 1 sends you to the first tab, clicking notification style 2 sends you to the 2nd tab?
Yes this is possible, just add a custom NSDictionary to the UILocalNotification userinfo property.
For example, add a type when you create the UILocalNotification:
myLocalnotification.userInfo = #{#"type" : #"openTab1"};
Then in the application:didReceiveLocalNotification: you could do:
if ([notification.userInfo[#"type"] isEqualToString:#"openTab1"]) {
// Your code to open tab1
}
UILocalNotifications supports the userInfo dictionary. You can add some information here to trigger the response you want. For instance you can create you own "action" dictionary:
#{ #"action" : #"open_tab_1"}
When you receive the notification you inspect the userInfo and check the action key and trigger the correct behavior by just checking the equality of 2 strings.
Consider something like the following example:
I have a library with books, books have a difficulty and genre.
Each book is an instance of some object and could be presented by a view controller (I.E. a collection view, where each cell is a book, of perhaps a detail view where only one book is displayed).
The data of these books can be updated in the background by some kind of synchronisation method. It is possible only one book is updated, or perhaps one genre.
I would like the classes (mostly the views) to receive a notification of updates. I would like these notifications to be pretty clear. So when all non-fiction books are updated this is what should be notified.
I could of course use separate notification names for each kind, but if we are talking about an entire library, a big collection view containing thousands of objects would mean registering too many observers. In this case the observer would perhaps choose to receive any notification on books, of maybe any of a genre.
What I am missing (or can't seem to figure out) in NSNotification is some kind of granularity to specify this need.
So in short:
Is there a way to tell NSNotification more specifically what kind of notifications I would like to receive/who to send it to?
Alternatively, can I attach an object to a notification? If so, I could model scope (like meta-data) of the notification in this object and let the receiver check this data.
Yes , you can do that, just specify your object and pack your meta-data in an dictionary and attach your notification as userInfo.and use this method to post notification :
- (void)postNotificationName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo
then you can access your notification like :
- (void)handleNotification:(NSNotification *)noti{
NSDictionary *userInfo = [noti userInfo];
YourObject *object = [noti object];
}
I'm trying to understand this two parameters of the method but i don't seems to understand it.
addObserverForName:object:queue:usingBlock:
I don't understand the description of 2 of the parameters in the method. Hope someone can explain it to me.
- (id)addObserverForName:(NSString *)name object:(id)obj queue:(NSOperationQueue *)queue usingBlock:(void (^)(NSNotification *))block
I don't understand this 2 lines:
name
The name of the notification for which to register the observer; that is, only notifications with this name are used to add the block to the operation queue.
If you pass nil, the notification center doesn’t use a notification’s name to decide whether to add the block to the operation queue.
what does it mean when the notification centre doesn't use notification name to decide whether to add block to the operation queue when it is nilled.
also,what notification name should i put in. I don't know.
and
obj
The object whose notifications you want to add the block to the operation queue.
If you pass nil, the notification center doesn’t use a notification’s sender to decide whether to add the block to the operation queue.
What object should i insert into this parameters.
nil name and valid object - all notifications from that object will be passed to the block.
Valid name and nil object, all notifications of that name by any object will be passed to the block.
Valid name and valid object - notifications of that name by that object will be passed to the block.
The name of the notification depends on what notification you want to observe, we can't tell you what to use from the description of your problem as it stands.
The documentation for the description of the name parameter sounds like it was copy-and-pasted from the description of object.
Notifications are sent with a string notification name:
[[NSNotificationCenter defaultCenter] postNotificationName: #"somethingHappened"
object: self];
Usually, but not always, the "object" in the post notification call is the object that is posting the notification. It might also be the object that the notification is about:
[[NSNotificationCenter defaultCenter] postNotificationName: #"aHouseCaughtFire"
object: theHouseThatCaughtFire];
That post notification call sends a message (e.g. "aHouseCaughtFire"), and the object parameter tells what object the event was associated with.
When you register for a notification, you can say that you care about a specific notification string (name), a particular object, or both. As the other poster said, if you pass in a nil notification name and a non-nil object, you'll be notified about all notifications sent with the object parameter you specified.
If you are going on vacation, you might want to register about all notifications regarding your house. (notification = nil, object = your house.)
Thus, you'd get "aHouseCaughtFire" notifications, "aHouseWasRobbed" notifications, and "aHouseGotaAPackage" notifications about your house, but not notifications about other houses.
If you are a fire department, you might want to register for all "aHouseCaughtFire" notifications, regardless of which house it is. Then the notification handler would look up the address of the specific house, and dispatch a fire truck.
I am working on a custom email notification for a WSS 3.0 solution. I am using a custom class inheriting from IAlertNotifyHandler to generate the email. There is a great example here that shows how this is done for an Immediate alert. Here is some of the code related to the SPAlertHandlerParams, which is used to get information about the alert and the item that triggered the alert.
SPAlertHandlerParams ahp;
int id = ahp.eventData[0].itemId; //gets the itemId of the item triggering the notification.
SPListItem myItem = list.GetItembyId(id);
For immediate alerts, this works great as the item I want is always at the [0] position of the eventData object. For a digest event, I thought I could just loop through all of the items in the ahp.eventData. Two problems with this.
First, it gives me all of the events where it is sending notifications, not just the ones for me. Second the eventData[0].itemId no longer points to a valid id on the list. It is 6-7 digit number instead of a 3 digit number.
Does anyone know the correct way to get to the alert information for digest emails?
Please let me know if you have any additional questions about this.
Thanks for your help!
For my project, I created a custom timer job (using the post by Andrew Connell) that mimics the Alert functionality. It runs overnight and queries for any users subscribed to my list with daily alerts. It then packages all of the new tasks into a custom email message.
I left the custom alert in place to suppress any daily notifications from the system. I just return 'True' so that alerts are not sent for tasks assigned to only 1 person. I suppose looking back on this, I could have run the query code in the custom alert and not need a separate timer job.