1

我有一个使用核心数据设置并使用 stackmob 托管的应用程序。我的用户登录和身份验证运行良好。用户可以创建新用户、登录和注销。问题:现在我希望用户能够相互交流。即,如果他们正在参加音乐会并想在我的应用程序上邀请其他用户,我将如何设置?我希望它类似于 Facebook:当有人发送邀请时,它会显示为收件人的通知。收件人可以单击通知并查看有关音乐会的详细信息。

这个过程叫什么?是否有一个很好的教程可以在 iOS 上实现这个?有什么书吗?

4

1 回答 1

2

在我看来,您将不得不使用推送通知。

您基本上必须将这些添加到您的应用程序委托类中:

- (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 
}

来自 Apple 的完整信息:http: //developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html

于 2013-03-02T17:27:42.890 回答