Domanda

I have an app that's setup with core data and hosted with stackmob. My user login and authentication is working great. Users are able to create a new user, login, and logout. Question: now I'd like the users to communicate with each other. I.e if they are attending a concert and would like to invite another user on my app, how would I set that up? I'd like it to be similar to Facebook: when someone sends an invite, it will show up as a notification for the recipient. The recipient can click on the notification and see the details about the concert.

What is this process called? Is there a good tutorial to implement this on iOS? Any book?

È stato utile?

Soluzione

Seems to me that you'll have to use push notifications.

You basically have to add these to your app delegate class:

- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   // other setup tasks here....
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

    UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (localNotif) {
        NSString *itemName = [localNotif.userInfo objectForKey:ToDoItemKey];
        [viewController displayItem:itemName];  // custom method
        application.applicationIconBadgeNumber = localNotif.applicationIconBadgeNumber-1;
    }
}

// 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);
}

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    NSString *itemName = [notif.userInfo objectForKey:ToDoItemKey]
    [viewController displayItem:itemName];  // custom method
    application.applicationIconBadgeNumber = notification.applicationIconBadgeNumber-1;
}

- (void)application:(NSApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    // Code to handle remote notifications 
}

Full information from Apple: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top