目前,我的一名PHP开发人员为我提供了适用于iOS设备的推送通知API

问题是:如果我在任何浏览器(Chrome / Safari / Firefox等)中使用各自的参数运行该api,则会在iOS设备的前台收到通知。但不是iOS应用程序(Xcode)本身

在我的应用中,我使用了如下代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 // Register for Push Notitications, if running on iOS 8
   if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
 }
}
#pragma mark
#pragma mark -- Push Notification Delegate Methods
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:   (UIUserNotificationSettings *)notificationSettings{
//register to receive notifications
[application registerForRemoteNotifications];
}
-(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{
// Prepare the Device Token for Registration (remove spaces and < >)
devToken = [[[[deviceToken description]
              stringByReplacingOccurrencesOfString:@"<"withString:@""]
             stringByReplacingOccurrencesOfString:@">" withString:@""]
            stringByReplacingOccurrencesOfString: @" " withString: @""];
NSLog(@"My token is: %@", devToken);
// My token is: cd2887c4093569b3eed142320f21a81e521e486cf5c40467390901d3a191398b
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:deviceToken forKey:@"deviceToken"];
}
-(void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error{
 NSLog(@"Failed to get token, error: %@", error);
}

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"%s..userInfo=%@",__FUNCTION__,userInfo);
}


我得到回应:(在didReceiveRemoteNotification中)

{
aps =     {
    alert = "You're login successfully";
    sound = default;
};


}

此消息未显示在状态栏(屏幕顶部)上。 iOS端(或PHP端)是否有任何问题

如果问题出在iOS方面->我该怎么做

这是我的测试推送通知API:

https://shopgt.com/mobile1/iphone/register.php?device_type=2&email=sukhpal@anaad.net&regId=4d1d9067cc1382ecb8b0532831cce7fc8eb6fc388a6139060cd84712407a0ae5

您能帮我解决这个问题吗

最佳答案

您需要自定义视图,以便在应用程序位于前景中时显示“推送通知横幅”。您可以使用JCNotificationBannerPresenter。使用以下链接遵循示例代码。

https://github.com/jcoleman/JCNotificationBannerPresenter

#import "JCNotificationCenter.h"
#import "JCNotificationBannerPresenterSmokeStyle.h"

- (void) application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)notification {
  NSString* title = @"Push Notification";
  NSDictionary* aps = [notification objectForKey:@"aps"];
  NSString* alert = [aps objectForKey:@"alert"];
  [JCNotificationCenter
   enqueueNotificationWithTitle:title
   message:alert
   tapHandler:^{
     NSLog(@"Received tap on notification banner!");
   }];
}


希望对您有帮助。

关于ios - iOS-推送通知问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35216294/

10-11 22:05
查看更多