Im trying to integrate Push Notifications in my iOS App. This is a Phonegap/Cordova Project. Everything is working well, without the APNS and Urban Airship.
What I have done till now? I got it to work, that I could send a Push Message from UA to my phone, but that was done with sample code from different forums and not the UA docs. So I startet to do it like in the docs of UA is showed. With that Im very confused and tried a lot.
So i did following:Took the Push Sample from UA and copied the code to AppDelegate.m what looks now like this:
// Create Airship singleton that's used to talk to Urban Airhship servers.
// Please populate AirshipConfig.plist with your info from http://go.urbanairship.com
[UAirship takeOff:takeOffOptions];
[[UAPush shared] resetBadge];//zero badge on startup
[[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
return YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
UALOG(@"Application did become active.");
[[UAPush shared] resetBadge]; //zero badge when resuming from background (iOS 4+)
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
UALOG(@"APN device token: %@", deviceToken);
// Updates the device token and registers the token with UA
[[UAPush shared] registerDeviceToken:deviceToken];
/*
* Some example cases where user notification may be warranted
*
* This code will alert users who try to enable notifications
* from the settings screen, but cannot do so because
* notications are disabled in some capacity through the settings
* app.
*
*/
/*
//Do something when notifications are disabled altogther
if ([application enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone) {
UALOG(@"iOS Registered a device token, but nothing is enabled!");
//only alert if this is the first registration, or if push has just been
//re-enabled
if ([UAirship shared].deviceToken != nil) { //already been set this session
NSString* okStr = @"OK";
NSString* errorMessage =
@"Unable to turn on notifications. Use the \"Settings\" app to enable notifications.";
NSString *errorTitle = @"Error";
UIAlertView *someError = [[UIAlertView alloc] initWithTitle:errorTitle
message:errorMessage
delegate:nil
cancelButtonTitle:okStr
otherButtonTitles:nil];
[someError show];
[someError release];
}
//Do something when some notification types are disabled
} else if ([application enabledRemoteNotificationTypes] != [UAPush shared].notificationTypes) {
UALOG(@"Failed to register a device token with the requested services. Your notifications may be turned off.");
//only alert if this is the first registration, or if push has just been
//re-enabled
if ([UAirship shared].deviceToken != nil) { //already been set this session
UIRemoteNotificationType disabledTypes = [application enabledRemoteNotificationTypes] ^ [UAPush shared].notificationTypes;
NSString* okStr = @"OK";
NSString* errorMessage = [NSString stringWithFormat:@"Unable to turn on %@. Use the \"Settings\" app to enable these notifications.", [UAPush pushTypeString:disabledTypes]];
NSString *errorTitle = @"Error";
UIAlertView *someError = [[UIAlertView alloc] initWithTitle:errorTitle
message:errorMessage
delegate:nil
cancelButtonTitle:okStr
otherButtonTitles:nil];
[someError show];
[someError release];
}
}
*/
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *) error {
UALOG(@"Failed To Register For Remote Notifications With Error: %@", error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UALOG(@"Received remote notification: %@", userInfo);
// Get application state for iOS4.x+ devices, otherwise assume active
UIApplicationState appState = UIApplicationStateActive;
if ([application respondsToSelector:@selector(applicationState)]) {
appState = application.applicationState;
}
[[UAPush shared] handleNotification:userInfo applicationState:appState];
[[UAPush shared] resetBadge]; // zero badge after push received
}
- (void)applicationWillTerminate:(UIApplication *)application {
[UAirship land];
}
Its pretty the same like before, but given from UA. Then i copied the files from the other sources folder from the Push Sample into my phonegap folder Supported Files including the AirshipConfig.plist. Also I set the Header Search Paths in the Build Settings to the Airship folder, what i copied before into the xCode project folder.
Now I get the error (6) "Use of undeclared identifier 'UAPush'" in the AppDeledate.m file. What can I do now?
Thanks for some help...