繁体   English   中英

方法声明缺少上下文

[英]Missing context for method declaration

我正在尝试使用delite studio在我的xcode项目中实现推送通知。

appdeladte.m中,我得到了错误:

方法声明缺少上下文

使用以下代码:-(void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo

有人可以帮我吗

//  AppDelegate.m

//

//  Copyright (c) 2015 Sherdle. All rights reserved.

//

#import "AppDelegate.h"

#import <GoogleMaps/GoogleMaps.h>

#import "Config.h"

#import "CommonBanner.h"

@implementation AppDelegate

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

{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


[self.window makeKeyAndVisible];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];


[GMSServices provideAPIKey: MAPS_API_KEY];

Config * obje = [[Config  alloc]init];


//TODO we also do this elsewhere, perhaps a global declaration would be better

NSIndexPath *selectedIndexPath  = [NSIndexPath indexPathForRow:0 inSection:0];

NSArray *sectionArray = [obje config];

NSArray *item = [[sectionArray objectAtIndex: selectedIndexPath.section] objectAtIndex:(selectedIndexPath.row + 1)];

rearViewController = [[RearTableViewController alloc]initWithNibName:@"RearTableViewController" bundle:nil];


UIViewController *viewController = [[rearViewController selectItem:item] init];


frontNav = [[UINavigationController alloc]initWithRootViewController:viewController];


rearNav = [[UINavigationController alloc]initWithRootViewController:rearViewController];


revealController = [[SWRevealViewController alloc]initWithRearViewController:rearNav frontViewController:frontNav];



[[UINavigationBar appearance] setBarTintColor:APP_THEME_COLOR];


[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]];


[[UINavigationBar appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, nil]];


[[UIApplication sharedApplication] registerForRemoteNotificationTypes:

(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];



if (ADS_ON){

[CommonBanner regitserProvider:[CommonBannerProvideriAd class]

withPriority:CommonBannerPriorityLow

requestParams:nil];


if (![ADMOB_UNIT_ID isEqualToString: @""]){


[CommonBanner regitserProvider:[CommonBannerProviderGAd class]

withPriority:CommonBannerPriorityHigh

requestParams:@{keyAdUnitID    : ADMOB_UNIT_ID,

keyTestDevices : @[]}];

}

[CommonBanner startManaging];

}

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {

[[UIApplication sharedApplication]

registerUserNotificationSettings:[UIUserNotificationSettings

settingsForTypes:(

UIUserNotificationTypeSound |

UIUserNotificationTypeAlert |

UIUserNotificationTypeBadge)

categories:nil]];

[[UIApplication sharedApplication] registerForRemoteNotifications];

}


else {

[[UIApplication sharedApplication]

registerForRemoteNotificationTypes:(

UIRemoteNotificationTypeBadge |

UIRemoteNotificationTypeSound |

UIRemoteNotificationTypeAlert)];

}

self.window.rootViewController = revealController;

return YES;

}

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

// Important note: If the user restores backup data to a new device or computer,

// or reinstalls the operating system, the device token changes.

self.restClient = [[DSRestClient alloc] init];

self.restClient.delegate = self;

[self.restClient registerWithUrl:@"http://myserver/pnfw/register/"

andToken:deviceToken];

//NSString *newToken = [deviceToken description];

//newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];

//newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];


//NSLog(@"My token is: %@", newToken);

}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error

{

// Manage failure

self.restClient = [[DSRestClient alloc] initWithKey:@""

andSecret:@""];

//NSLog(@"Failed to get token, error: %@", error);

}

- (void)restClientRegistered:(DSRestClient *)client

{


}

- (void)restClient:(DSRestClient *)client registerFailedWithError:(NSError *)error

{

}

- (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, this method is called instead of applicationWillTerminate: when the user quits.

}

- (void)applicationWillEnterForeground:(UIApplication *)application

{

// Called as part of the 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. Save data if appropriate. See also applicationDidEnterBackground:.

}

@end

//@implementation AppDelegate () <DSRestClientDelegate>

//- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

//Receiving Push Notifications

//You can retrieve notification data with the following code in the AppDelegate:

- (void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo

{


// This method is called if the app is running in the foreground, but also

// if the user press "show" on the notification AND the app is in the background



NSDictionary *aps = userInfo[@"aps"];

NSString *title = aps[@"alert"];

NSString *eventId = userInfo[@"id"];



if (application.applicationState == UIApplicationStateActive)

{

// If the application is foremost and visible when the system delivers the notification,

// no alert is shown, no icon is badged, and no sound is played. So we need to display a

// notification to the user when the app is actually running in the foreground


}

else

{


// App was just brought from background to foreground because the user tapped on the notification

}

//Subscribing


restClient.delegate = self;

[restClient linkWithUrl:@"http://myserver/pnfw/register/"

andEmail:email];

//Those delegate methods are called:

- (void)restClientLinked:(DSRestClient *)client

withEmail:(NSString *)email

andCustomParameters:(NSDictionary *)customParameters;

- (void)restClient:(DSRestClient *)client

linkFailedWithError:(NSError *)error;

//You can add any custom fields to subscribers using the hook pnfw_register_custom_parameters and use this method:

restClient.delegate = self;

[restClient linkWithUrl:@"http://myserver/pnfw/register/"

andEmail:email

andCustomParameters:@{@"key": value}];

//Unregistering

//This method allows client device to unregister itself from push notifications. If the last token associated with an anonymous user is removed, the user is also removed.

restClient.delegate = self;

[restClient unregisterWithUrl:@"http://myserver/pnfw/unregister/"];

//Those delegate methods are called:

- (void)restClientUnregistered:(DSRestClient *)client;

- (void)restClient:(DSRestClient *)client

unregisterFailedWithError:(NSError *)error;

//Retrieving Posts

NSDate *timestamp = nil;

restClient.delegate = self;

[restClient loadPostsWithUrl:@"http://myserver/pnfw/posts/"

andTimestamp:timestamp];

//Those delegate methods are called:

- (void)restClient:(DSRestClient *)client

loadedPosts:(PNPosts *)posts;

- (void)restClientPostsUnchanged:(DSRestClient *)client;

- (void)restClient:(DSRestClient *)client

loadPostsFailedWithError:(NSError *)error;

//Retrieving specific Post

//This method returns the details of the specified post.

restClient.delegate = self;

[restClient loadPostWithUrl:@"http://myserver/pnfw/posts/"

andIdentifier:identifier];

//Those delegate methods are called:

- (void)restClient:(DSRestClient *)client

loadedPost:(PNPost *)post;

- (void)restClientPostUnchanged:(DSRestClient *)client;

- (void)restClient:(DSRestClient *)client

loadPostFailedWithError:(NSError *)error;

//Retrieving Categories

//This method allows client device to retrieve the list of post categories.

NSDate *timestamp = nil;

restClient.delegate = self;

[restClient loadCategoriesWithUrl:@"http://myserver/pnfw/categories/"

andTimestamp:timestamp;

//Those delegate methods are called:

- (void)restClient:(DSRestClient *)client

loadedCategories:(PNCategories *)categories;


- (void)restClientCategoriesUnchanged:(DSRestClient *)client;


- (void)restClient:(DSRestClient *)client

loadCategoriesFailedWithError:(NSError *)error;


//Updating Categories

restClient.delegate = self;

[restClient updateCategoryWithUrl:@"http://Myserver/pnfw/categories/"

andIdentifier:identifier

andExclude:exclude;

//Those delegate methods are called:

- (void)restClientCategoryUpdated:(DSRestClient *)client;

- (void)restClient:(DSRestClient *)client

updateCategoryFailedWithError:(NSError *)error;


//Retrieving User Categories

NSDate *timestamp = nil;

restClient.delegate = self;

[restClient loadUserCategoriesWithUrl:@"http://myserver/pnfw/user-categories/"

andTimestamp:timestamp];

//Those delegate methods are called:

- (void)restClient:(DSRestClient *)client

loadedUserCategories:(PNUserCategories *)categories;


- (void)restClientUserCategoriesUnchanged:(DSRestClient *)client;



- (void)restClient:(DSRestClient *)client

loadUserCategoriesFailedWithError:(NSError *)error;


//Updating User Categories

restClient.delegate = self;

[restClient updateUserCategoryWithUrl:@"http://myserver/pnfw/user-categories/"

andIdentifier:identifier];

//Those delegate methods are called:


- (void)restClientUserCategoryUpdated:(DSRestClient *)client;


- (void)restClient:(DSRestClient *)client

updateUserCategoryFailedWithError:(NSError *)error;

您将方法放在@end ,因此编译器不知道它属于哪个类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM