-1

当我尝试输入此代码时,Xcode 说我“使用了未声明的标识符 'completedWithResult'”。这是 Quickblox 上推送通知的代码。有一段代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    /// Set QuickBlox credentials (You must create application in admin.quickblox.com)
    [QBSettings setApplicationID:XX];
    [QBSettings setAuthorizationKey:@"XX"];
    [QBSettings setAuthorizationSecret:@"XX"];
    //
    // If you use Push Notifications - you have to use lines bellow when you upload your application to Apple Store or create AdHoc.
    //

    [QBSettings useProductionEnvironmentForPushNotifications:YES];

    QBASessionCreationRequest *extendedAuthRequest = [QBASessionCreationRequest request];
    extendedAuthRequest.devicePlatorm = DevicePlatformiOS;
    extendedAuthRequest.deviceUDID = [[UIDevice currentDevice] uniqueIdentifier];
    extendedAuthRequest.userLogin = @"yourUserLogin";
    extendedAuthRequest.userPassword = @"yourUserPassword";

    [QBAuth createSessionWithExtendedRequest:extendedAuthRequest delegate:self];

    // QuickBlox queries delegate
    - (void)completedWithResult:(Result *)result{
        if(result.success){

            // Create session result
            if([result isKindOfClass:QBAAuthSessionCreationResult.class]){
                // register for receive push notifications
                [QBMessages TRegisterSubscriptionWithDelegate:self];

                // Register for receive push notifications result
            }else if([result isKindOfClass:QBMRegisterSubscriptionTaskResult.class]){
                // Congrats! Now you can receive Push Notifications!
            }
        }
    }

错误在这一行:

 // QuickBlox queries delegate
        - (void)completedWithResult:(Result *)result{
            if(result.success){

它说'使用未声明的标识符'completedWithResult''

请问有人可以帮忙吗?谢谢!

4

2 回答 2

4

您正在另一个方法中实现一个方法。这在 Objective-C 中是不允许的。application:didFinishLaunchingWithOptions:您可能只是错过了该方法的右括号。}用上面的第二个 ( completedWithResult:) 方法关闭它。

于 2013-03-28T12:34:57.660 回答
2

您不能在 Objective-C 的方法中实现方法。确保在类中实现该方法,而不是其他方法。

如果您还没有弄清楚,委托模式是 Cocoa 框架的一个简单但重要的部分:将您的方法放在委托类中,您代码的其他组件(在本例中为 QBAuth)将调用稍后。

于 2013-03-28T12:42:09.803 回答