1

帮助!我找不到什么问题。我的代码已启动并且大部分都在运行,我需要合并 Urban Air 推送通知,但我的代码有问题。如果有更好或不同的方法来合并它而不会出现我的错误,我将不胜感激。我从 Urban Airmail 中获取了这段代码。我不确定示例应用程序中包含哪些内容以及不包含哪些内容。现在我的代码。我会记下我在哪里得到错误它们是杂散/错误和预期的;b4 : 错误

如果你能修复代码,那就太棒了!

    //
//  SuperSlickAppDelegate.m
//  SuperSlick
//
//  Created by  on 8/2/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import <SystemConfiguration/SCNetworkReachability.h>
#include <netinet/in.h> 
#import "SuperSlickAppDelegate.h"
#import "SuperSlickViewController.h"
#import "Reachability.h"




@implementation SuperSlickAppDelegate

@synthesize window;
@synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
#define kApplicationKey @"rnftzaemRp2HJMsNjwZvGQ"
#define kApplicationSecret @"X1XdTjdWQIaL72e-gXew5A"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  
    // Override point for customization after application launch.
    Reachability *r = [Reachability reachabilityWithHostName:@"google.com"];

    NetworkStatus internetStatus = [r currentReachabilityStatus];

    if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
    {
        UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"You require an internet connection via WiFi or cellular network to use this! Try the settings app for WiFi Connectivity." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [myAlert show];
        [myAlert release];
    }



    //Register for notifications
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)];
     //ERROR HERE in line above Stray 357

    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {
        //ERROR HERE Wrong type argument to unary minus + stray

        // Get a hex string from the device token with no spaces or < >
        self.deviceToken = [[[[_deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
                             stringByReplacingOccurrencesOfString:@">" withString:@""]
                            stringByReplacingOccurrencesOfString: @" " withString: @""];

        NSLog(@"Device Token: %@", self.deviceToken);

        if ([application enabledRemoteNotificationTypes] == 0) {
            NSLog(@"Notifications are disabled for this application. Not registering with Urban Airship");
            return;
        }

        // this is straight out of the UA sample code
        NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
        NSString *UAServer = @"https://go.urbanairship.com";
        NSString *urlString = [NSString stringWithFormat:@"%@%@%@/", UAServer, @"/api/device_tokens/", self.deviceToken];
        NSURL *url = [NSURL URLWithString:  urlString];
        ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
        request.requestMethod = @"PUT";

        // Authenticate to the server
        request.username = kApplicationKey;
        request.password = kApplicationSecret;

        [request setDelegate:self];
        [request setDidFinishSelector: @selector(registrationSuccessMethod:)]; // if you want to do something with the token
        [request setDidFailSelector: @selector(requestWentWrong:)];
        [queue addOperation:request];
    }

    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *) error {
        NSLog(@"Failed to register with error: %@", error);
    }

    - (void)requestWentWrong: (ASIHTTPRequest *)request {

        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        NSError *_error = [request error];

        NSLog(@"ERROR: NSError query result: %@", _error);

        UIAlertView *someError = [[UIAlertView alloc] initWithTitle:
                                  @"Network error" message: NSLocalizedString( @"Error registering with notifiction server",
                                                                              @"Error registering with notifiction server")
                                                           delegate: self
                                                  cancelButtonTitle: @"OK"
                                                  otherButtonTitles: nil];
        [someError show];
        [someError release];
    }
    // Add the view controller's view to the window and display.
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}
}



- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}

#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}


@end

有问题的新代码:

    //Register for notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)]; 
    ;}}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {
    //ERROR HERE Wrong type argument to unary minus and semi colon b4 
4

2 回答 2

4

看起来您从未结束过您的应用程序:didFinishLaunchingWithOptions: 方法 - 您应该在此行之后有一个结束括号:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes...

所以它应该是这样的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  
    ...

     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)];
     //ERROR HERE in line above Stray 357
}

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {

    ...

}

那应该这样做。

对于您的第二个代码块 - 如果没有看到周围的代码,很难看到您正在尝试做什么......您可能不应该:

;}}

它可能应该只是:

}
于 2010-08-05T04:04:11.910 回答
1

如果您正在寻找不平衡的括号,那么这可能是给您带来麻烦的部分:

    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}
}
于 2010-08-05T04:10:20.353 回答