2010-08-05 33 views
1

帮助! 我无法找到最新的错误。我的代码已经启动,大部分都在运行,我需要整合Urban Air推送通知,并且我的代码有问题。如果有更好或不同的方式来合并这个没有我的错误,我会很感激。 我从城市航空邮件中汲取了这段代码。我不确定包括什么和不能从示例应用中获得什么。 现在为我的代码。我会告诉我哪里有错误他们是流浪/错误和预期; b4: 错误是我还是xcode ...我的大括号有些问题,它只是导致错误!请帮忙! iPhone SDK + Urban Push

如果您可以修复那些令人敬畏的代码!

// 
// 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 
+0

我更新了我的答案以解决您的第二个代码块,请参阅下文。 – codykrieger 2010-08-06 10:21:01

回答

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 { 

    ... 

} 

这应该做到这一点。

对于你的第二个代码块 - 没有看到周围的代码是很难看到你正在试图做...你可能不应该有什么:

;}} 

应该可能只是:

} 
+0

我需要15个代表。抱歉!将尽快完成! – Sum 2010-08-06 04:36:43

+0

下面就让我来粘贴错误行 \t \t //注册通知 \t \t [UIApplication的sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; \t \t;}} \t - (无效)应用:(UIApplication的*)应用didRegisterForRemoteNotificationsWithDeviceToken:(NSData的*)_ deviceToken { \t \t //错误该处错误类型参数元负和分号B4 – Sum 2010-08-06 04:53:36

+0

不适把它在原帖也是! – Sum 2010-08-06 04:53:58

1

如果您正在寻找不对称的括号,那么这可能是有问题的时候部分:

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

    return YES; 
} 
} 
相关问题